답안 #768346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768346 2023-06-28T00:33:28 Z iamjiamingliu 은행 (IZhO14_bank) PyPy 3
0 / 100
32 ms 18200 KB
people = [int(i) for i in input().split()]
banknotes = [int(i) for i in input().split()]

leftover = [-1 for _ in range(1 << len(banknotes))]
people_covered = [-1 for _ in range(1 << len(banknotes))]
leftover[0] = 0
people_covered[0] = 0
for s in range(1, 1 << len(banknotes)):
	for last in range(len(banknotes)):
		if (s & (1 << last)) == 0:
			continue
		prev = s & ~(1 << last)
		if people_covered[prev] == -1:
			continue

		new_amt = leftover[prev] + banknotes[last]
		# the salary of the current person we're going to try to pay
		curr_target = people[people_covered[prev]]
		# if it's still not enough, just increment the leftover pile
		if new_amt < curr_target:
			people_covered[s] = people_covered[prev]
			leftover[s] = new_amt
			"""
			or it's exactly right, in which case reset the leftover count
			and increment the covered amount
			"""
		elif new_amt == curr_target:
			people_covered[s] = people_covered[prev] + 1
			leftover[s] = 0

	# we've covered all the people!
	if people_covered[s] == len(banknotes):
		print("YES")
		exit()
        
print("NO")
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 18200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 18136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 18184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 18200 KB Output isn't correct
2 Halted 0 ms 0 KB -