본문 바로가기

algorithm/greedy

[백준OJ] #2875 ; 대회 or 인턴

[해결 IDEA]

- 여학생은 2명씩 남학생은 1명씩 빠지게 된다

- 팀을 만들다 남은 인원수가 인턴수보다 작으면 안된다 (=종료조건)

 

[CODE]

import sys
input = sys.stdin.readline

def makeTeam(n,m,k):
	team=0
	while True:
		n-=2
		m-=1
		# 인원수에서 빼주면서,team 을 만들어
		if n<0 or m<0 or (n+m)<k: #종료조건 
			break
		team += 1
	print(team)

if __name__ == '__main__':
	N, M, K = list(map(int, input().split()))
	makeTeam(N,M,K)

- 56ms