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
range = xrange
raw_input = stdin.readline
N = int(raw_input())
L = [None]*N
for i in range(N):
a, b = map(int, raw_input().split())
L[i] = (a, b)
L.sort()
ans = L[0][1]
DP = [ [-1]*N for i in range(N) ]
for i in range(N):
a, b = L[i]
DP[i][i] = b
ans = max(ans, b)
for k in range(1, N-1):
for i in range(N-k):
j = i+k
a, b = L[j]
a_, b_ = L[j-1]
DP[i][j] = DP[i][j-1] + b - a + a_
ans = max(ans, DP[i][j])
print ans
# | 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... |