Submission #791836

#TimeUsernameProblemLanguageResultExecution timeMemory
791836BoomydayArt Exhibition (JOI18_art)Pypy 3
50 / 100
1000 ms113168 KiB
from sys import stdin bestScore = 0 N = int(input()) arts = [] INF = 10**18 for _ in range(N): a, b = map(int, stdin.readline().split()) arts.append((a, b)) arts.sort(key=lambda x: x[0]) A, B = [], [] for a, b in arts: A.append(a) B.append(b) prefs = [0] for i in range(N): prefs.append(prefs[-1] + B[i]) prefs_orig = prefs.copy() for i in range(N): prefs[i+1] -= A[i] suffix_maxs = [-INF]*(N+1) suffix_maxs[-1] = prefs[-1] for i in range(N-1, -1, -1): suffix_maxs[i] = max(suffix_maxs[i+1], prefs[i]) mx = max(B) for st in range(N): bestmx = suffix_maxs[st+1] mx = max(mx, bestmx-prefs_orig[st]+A[st]) print(mx)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...