답안 #632992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632992 2022-08-21T11:25:05 Z karolb2011 Potatoes and fertilizers (LMIO19_bulves) Python 3
0 / 100
15 ms 2944 KB
import sys
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)
w=[0 for i in range(p+1)]
for c in s:
    if c<0:
        ww-=c
        c=0
    elif c>p:
        ww+=c-p
        c=p
    for j in range(p+1):
        if j<=c:
            w[j]+=c-j
        else:
            w[j]+=j-c
            if w[j]>=w[j-1]:
                mm=w[j-1]
                break  
    for k in range(j,p+1):
        w[k]=mm
print(w[p]+ww)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2944 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2944 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2944 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2944 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2944 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -