import sys
input = sys.stdin.readline
n=int(input())
w=0
t=0
p=0
s=[]
r=[]
for i in range(n):
pi,bi=list(map(int,input().split()))
p+=pi-bi
if p>=1:
w+=p
t+=p-1
else:
w-=p
t-=p-1
s.append(w)
r.append(t)
if p>0:
for i in range(n):
w=min(w,s[i]-r[i]+t)
print(w)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2984 KB |
Output is correct |
3 |
Correct |
19 ms |
3040 KB |
Output is correct |
4 |
Correct |
103 ms |
8268 KB |
Output is correct |
5 |
Correct |
214 ms |
13688 KB |
Output is correct |
6 |
Correct |
460 ms |
30188 KB |
Output is correct |
7 |
Correct |
903 ms |
58440 KB |
Output is correct |
8 |
Correct |
882 ms |
63408 KB |
Output is correct |
9 |
Correct |
979 ms |
62740 KB |
Output is correct |
10 |
Correct |
890 ms |
55708 KB |
Output is correct |
11 |
Correct |
933 ms |
58632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2984 KB |
Output is correct |
3 |
Correct |
19 ms |
3040 KB |
Output is correct |
4 |
Correct |
103 ms |
8268 KB |
Output is correct |
5 |
Correct |
214 ms |
13688 KB |
Output is correct |
6 |
Correct |
460 ms |
30188 KB |
Output is correct |
7 |
Correct |
903 ms |
58440 KB |
Output is correct |
8 |
Correct |
882 ms |
63408 KB |
Output is correct |
9 |
Correct |
979 ms |
62740 KB |
Output is correct |
10 |
Correct |
890 ms |
55708 KB |
Output is correct |
11 |
Correct |
933 ms |
58632 KB |
Output is correct |
12 |
Correct |
349 ms |
18404 KB |
Output is correct |
13 |
Correct |
694 ms |
40260 KB |
Output is correct |
14 |
Execution timed out |
1085 ms |
65120 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2984 KB |
Output is correct |
3 |
Incorrect |
13 ms |
2772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2984 KB |
Output is correct |
3 |
Correct |
19 ms |
3040 KB |
Output is correct |
4 |
Incorrect |
13 ms |
2772 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2984 KB |
Output is correct |
3 |
Correct |
19 ms |
3040 KB |
Output is correct |
4 |
Incorrect |
13 ms |
2772 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |