import sys
input = sys.stdin.readline
n=int(input())
w=0
t=0
p=0
s=[]
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-t)
if p>0:
w=min(w,t,min(s)+t)
print(w)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2888 KB |
Output is correct |
3 |
Correct |
18 ms |
2976 KB |
Output is correct |
4 |
Correct |
102 ms |
4868 KB |
Output is correct |
5 |
Correct |
213 ms |
6776 KB |
Output is correct |
6 |
Correct |
431 ms |
12708 KB |
Output is correct |
7 |
Correct |
884 ms |
22736 KB |
Output is correct |
8 |
Correct |
892 ms |
22752 KB |
Output is correct |
9 |
Correct |
916 ms |
22728 KB |
Output is correct |
10 |
Correct |
797 ms |
19636 KB |
Output is correct |
11 |
Correct |
864 ms |
22628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2888 KB |
Output is correct |
3 |
Correct |
18 ms |
2976 KB |
Output is correct |
4 |
Correct |
102 ms |
4868 KB |
Output is correct |
5 |
Correct |
213 ms |
6776 KB |
Output is correct |
6 |
Correct |
431 ms |
12708 KB |
Output is correct |
7 |
Correct |
884 ms |
22736 KB |
Output is correct |
8 |
Correct |
892 ms |
22752 KB |
Output is correct |
9 |
Correct |
916 ms |
22728 KB |
Output is correct |
10 |
Correct |
797 ms |
19636 KB |
Output is correct |
11 |
Correct |
864 ms |
22628 KB |
Output is correct |
12 |
Correct |
233 ms |
7828 KB |
Output is correct |
13 |
Correct |
536 ms |
14808 KB |
Output is correct |
14 |
Correct |
888 ms |
22808 KB |
Output is correct |
15 |
Correct |
890 ms |
22676 KB |
Output is correct |
16 |
Correct |
912 ms |
26928 KB |
Output is correct |
17 |
Correct |
791 ms |
24640 KB |
Output is correct |
18 |
Correct |
17 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2888 KB |
Output is correct |
3 |
Correct |
17 ms |
2900 KB |
Output is correct |
4 |
Incorrect |
13 ms |
2744 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2888 KB |
Output is correct |
3 |
Correct |
18 ms |
2976 KB |
Output is correct |
4 |
Incorrect |
13 ms |
2744 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2888 KB |
Output is correct |
3 |
Correct |
18 ms |
2976 KB |
Output is correct |
4 |
Incorrect |
13 ms |
2744 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |