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,min(s)+t)
print(w)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2928 KB |
Output is correct |
3 |
Correct |
21 ms |
2984 KB |
Output is correct |
4 |
Correct |
104 ms |
4788 KB |
Output is correct |
5 |
Correct |
179 ms |
6824 KB |
Output is correct |
6 |
Correct |
442 ms |
12736 KB |
Output is correct |
7 |
Correct |
905 ms |
22704 KB |
Output is correct |
8 |
Correct |
864 ms |
22700 KB |
Output is correct |
9 |
Correct |
851 ms |
22684 KB |
Output is correct |
10 |
Correct |
809 ms |
19664 KB |
Output is correct |
11 |
Correct |
863 ms |
22576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2928 KB |
Output is correct |
3 |
Correct |
21 ms |
2984 KB |
Output is correct |
4 |
Correct |
104 ms |
4788 KB |
Output is correct |
5 |
Correct |
179 ms |
6824 KB |
Output is correct |
6 |
Correct |
442 ms |
12736 KB |
Output is correct |
7 |
Correct |
905 ms |
22704 KB |
Output is correct |
8 |
Correct |
864 ms |
22700 KB |
Output is correct |
9 |
Correct |
851 ms |
22684 KB |
Output is correct |
10 |
Correct |
809 ms |
19664 KB |
Output is correct |
11 |
Correct |
863 ms |
22576 KB |
Output is correct |
12 |
Correct |
245 ms |
7928 KB |
Output is correct |
13 |
Correct |
551 ms |
14736 KB |
Output is correct |
14 |
Correct |
925 ms |
22932 KB |
Output is correct |
15 |
Incorrect |
900 ms |
27608 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2928 KB |
Output is correct |
3 |
Incorrect |
14 ms |
2772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2928 KB |
Output is correct |
3 |
Correct |
21 ms |
2984 KB |
Output is correct |
4 |
Incorrect |
14 ms |
2772 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
2928 KB |
Output is correct |
3 |
Correct |
21 ms |
2984 KB |
Output is correct |
4 |
Incorrect |
14 ms |
2772 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |