| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1350997 | akshar_7 | Potatoes and fertilizers (LMIO19_bulves) | Pypy 3 | 204 ms | 280028 KiB |
import heapq
from sys import stdin
input = stdin.readline
def main():
n = int(input())
#n,q = map(int, input().split())
#a = [int(i) for i in input().split()]
#b = [int(i) for i in input().split()]
#c = [int(i) for i in input().split()]
#c = [list(i) for i in input().split()]
#b = [int(i) for i in input().split()]
#s = input().strip()
ans = sma = smb = 0
d = []
p = [0]*n
for i in range(n):
a,b = map(int, input().split())
d.append((a,b))
sma +=a; smb +=b
p[i] = sma - smb
E = sma - smb
sm = p[0]
if sm<0:
ans -= sm; sm=0
if sm>E:
ans += (sm-E); sm=E
l = [-sm]
for i in range(1,n):
sm = p[i]
if sm<0:
ans -= sm; sm=0
if sm>E:
ans += (sm-E); sm=E
heapq.heappush(l, -sm)
if sm < -l[0]:
ans += abs(-l[0] - sm)
heapq.heappop(l)
heapq.heappush(l, -sm)
return ans
T = 1#int(input())
for __ in range(T):
print(main())Compilation message (stdout)
| # | 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... | ||||
