1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| N = int(input())
eggs = list()
for _ in range(N):
eggs.append(list(map(int, input().split())))
answer = 0
def dfs(eggs, idx):
global answer
if idx == N:
answer = max(answer, len([s for s,w in eggs if s < 1]))
return
if eggs[idx][0] < 1:
dfs(eggs, idx+1)
return
if len([s for s,w in eggs if s < 1]) >= N-1:
answer = max(answer, N-1)
return
for target in range(N):
if target != idx and eggs[target][0] > 0:
eggs[target][0] -= eggs[idx][1]
eggs[idx][0] -= eggs[target][1]
dfs(eggs, idx+1)
eggs[target][0] += eggs[idx][1]
eggs[idx][0] += eggs[target][1]
dfs(eggs, 0)
print(answer)
|