This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |