Submission #1091518

#TimeUsernameProblemLanguageResultExecution timeMemory
1091518vjudge1Potatoes and fertilizers (LMIO19_bulves)Cpython 3
24 / 100
1044 ms52020 KiB
n = int(input()) a = [0] * n b = [0] * n for i in range(n): x, y = map(int, input().split()) a[i] = x b[i] = y # subtask 1 only ans = 0 extra = 0 suffix = [] for i in range(n): ans += abs(extra) extra += a[i] - b[i] suffix.append(-1 if extra > 0 else 1) if extra == 1: # subtask 2 current = ans suffix.pop() total = 0 while len(suffix) > 0: total += suffix.pop() ans = min(ans, current + total) print(ans)
#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...