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=[]
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 |
---|
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... |