This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
from sys import stdin
input = stdin.readline
def solve():
n = int(input())
artworks = []
for i in range(n):
artworks.append(list(map(int, input().split())))
artworks.sort()
maxx = -10**18
ans = 0
pref = 0
for a, b in artworks:
maxx = max(a - pref, maxx)
pref += b
ans = max(maxx + pref - a, ans)
print(ans)
solve()
# | 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... |