Skip to content

Commit

Permalink
22.08.05
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 5, 2022
1 parent 99c1b4c commit bf3f706
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions BAEKJOON/15554_전시회.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from collections import defaultdict
import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
dic = defaultdict(int)
for _ in range(N):
a, b = map(int, input().split())
dic[a] = dic[a] + b

items = sorted(dic.items())
answer, dp, pre_key = 0, 0, 0
for i, (key, value) in enumerate(items):
if i:
dp = max(value, dp + value - key + pre_key)
else:
dp = value
answer, pre_key = max(answer, dp), key
print(answer)

0 comments on commit bf3f706

Please sign in to comment.