From bf3f7066a2f6262112b5a79693874c232adee035 Mon Sep 17 00:00:00 2001 From: delena0702 <57484961+delena0702@users.noreply.github.com> Date: Fri, 5 Aug 2022 17:56:23 +0900 Subject: [PATCH] 22.08.05 --- ...4_\354\240\204\354\213\234\355\232\214.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "BAEKJOON/15554_\354\240\204\354\213\234\355\232\214.py" diff --git "a/BAEKJOON/15554_\354\240\204\354\213\234\355\232\214.py" "b/BAEKJOON/15554_\354\240\204\354\213\234\355\232\214.py" new file mode 100644 index 0000000..8f55cc8 --- /dev/null +++ "b/BAEKJOON/15554_\354\240\204\354\213\234\355\232\214.py" @@ -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) \ No newline at end of file