N = int(input())
stol = []
for i in range(N):
Ti, Zi = map(int, input().split())
stol += [[i, Ti, Zi]]
#print(stol)
stol = sorted(stol, key = lambda x: x[2])
#print(stol)
for i in range(N-1):
koliko = stol[i][1]
j = i + 1
while koliko > 0 and j < N:
t = stol[j][1]
stol[j][1] = min(stol[j][2], stol[j][1] + koliko)
koliko = koliko - (stol[j][1] - t)
stol[i][1] = koliko
j += 1
#print(stol)
stol = sorted(stol, key = lambda x: x[0])
#print(stol)
ukupno = 0
for i in range(N):
if stol[i][1] == 0:
ukupno += 1
print(ukupno)
for i in range(N):
print(stol[i][1], end = ' ')
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3400 KB |
Output is correct |
2 |
Correct |
25 ms |
3300 KB |
Output is correct |
3 |
Correct |
29 ms |
3428 KB |
Output is correct |
4 |
Correct |
26 ms |
3356 KB |
Output is correct |
5 |
Correct |
25 ms |
3300 KB |
Output is correct |
6 |
Correct |
28 ms |
3356 KB |
Output is correct |
7 |
Correct |
29 ms |
3368 KB |
Output is correct |
8 |
Correct |
460 ms |
3668 KB |
Output is correct |
9 |
Correct |
136 ms |
3476 KB |
Output is correct |
10 |
Correct |
254 ms |
3648 KB |
Output is correct |