import sys
input = sys.stdin.readline
n=int(input())
t=0
p=0
s=[]
ww=0
for i in range(n):
pi,bi=list(map(int,input().split()))
p+=pi-bi
s.append(p)
w=[0 for i in range(p+1)]
for c in s:
q=False
if c<0:
ww-=c
c=0
elif c>p:
ww+=c-p
c=p
for j in range(p+1):
z=c-j
if z>=0:
w[j]+=z
else:
w[j]-=z
if w[j]>=w[j-1]:
mm=w[j-1]
q=True
break
if q:
for k in range(j,p+1):
w[k]=mm
print(w[p]+ww)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2900 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
20 ms |
2992 KB |
Output is correct |
4 |
Correct |
118 ms |
4972 KB |
Output is correct |
5 |
Correct |
228 ms |
6924 KB |
Output is correct |
6 |
Correct |
574 ms |
13004 KB |
Output is correct |
7 |
Execution timed out |
1100 ms |
22720 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2900 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
20 ms |
2992 KB |
Output is correct |
4 |
Correct |
118 ms |
4972 KB |
Output is correct |
5 |
Correct |
228 ms |
6924 KB |
Output is correct |
6 |
Correct |
574 ms |
13004 KB |
Output is correct |
7 |
Execution timed out |
1100 ms |
22720 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2900 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
13 ms |
2900 KB |
Output is correct |
4 |
Correct |
523 ms |
3080 KB |
Output is correct |
5 |
Execution timed out |
1095 ms |
3116 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2900 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
20 ms |
2992 KB |
Output is correct |
4 |
Correct |
13 ms |
2900 KB |
Output is correct |
5 |
Correct |
523 ms |
3080 KB |
Output is correct |
6 |
Execution timed out |
1095 ms |
3116 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2900 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
20 ms |
2992 KB |
Output is correct |
4 |
Correct |
13 ms |
2900 KB |
Output is correct |
5 |
Correct |
523 ms |
3080 KB |
Output is correct |
6 |
Execution timed out |
1095 ms |
3116 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |