Submission #633062

#TimeUsernameProblemLanguageResultExecution timeMemory
633062karolb2011Potatoes and fertilizers (LMIO19_bulves)Cpython 3
54 / 100
1091 ms32388 KiB
import sys import heapq as hq input = sys.stdin.readline n=int(input()) t=0 p=0 s=[] ww=0 for i in range(n): pi,bi=list(map(int,input().split())) p+=pi-bi s.append(p) if p==0: for c in s: ww+=abs(c) else: w=[] for c in s: if c<0: ww-=c c=0 elif c>p: ww+=c-p c=p hq.heappush(w,-c) hq.heappush(w,-c) ww+=abs(-hq.heappop(w)-c) print(ww)
#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...