Submission #633089

#TimeUsernameProblemLanguageResultExecution timeMemory
633089karolb2011Potatoes and fertilizers (LMIO19_bulves)Pypy 3
100 / 100
604 ms46072 KiB
import sys import heapq as hq input = sys.stdin.readline n=int(input()) p=0 s=[] z=0 for i in range(n): a,b=list(map(int,input().split())) p+=b-a s.append(p) w=[] for c in s: if c>0: z+=c c=0 elif c<p: z-=c-p c=p hq.heappush(w,c) if w[0]<c: hq.heappush(w,c) z+=abs(hq.heappop(w)-c) print(z)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...