From 626531b623269d899b1ee3224fd79ee4b54cd493 Mon Sep 17 00:00:00 2001 From: bsyzch Date: Tue, 10 Aug 2021 22:00:49 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=AC=EB=AF=BC=20=EB=B0=B1=EC=A4=80?= =?UTF-8?q?=EC=88=99=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200_1202.py" | 41 ++++++++++++++++--- .../\353\260\261\354\244\200_1541.py" | 22 ++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_1541.py" diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_1202.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_1202.py" index efb361b..da2bacd 100644 --- "a/cmkim/BaekJoon/\353\260\261\354\244\200_1202.py" +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_1202.py" @@ -1,11 +1,40 @@ +import heapq +import sys +input = sys.stdin.readline n, k = map(int, input().split()) -jewel = [[0, 0] for _ in range(n)] -bag = [0 for _ in range(k)] + +jewel = [] +bags = [] + for i in range(n): - jewel[i] = list(map(int, input().split())) + w, v = map(int, input().split()) + heapq.heappush(jewel, (w, v)) for i in range(k): - bag[i] = int(input()) + heapq.heappush(bags, int(input())) + +result = 0 +selected = [] +for _ in range(k): + bags_weight = heapq.heappop(bags) + + while jewel and bags_weight >= jewel[0][0]: + tmp = heapq.heappop(jewel) + w, v = tmp[0], tmp[1] + heapq.heappush(selected, -v) + + if selected: + result -= heapq.heappop(selected) -print(jewel) -print(bag) \ No newline at end of file +print(result) +''' +4 4 +1 100 +2 200 +13 300 +10 500 +14 +3 +12 +1 +''' \ No newline at end of file diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_1541.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_1541.py" new file mode 100644 index 0000000..adde54f --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_1541.py" @@ -0,0 +1,22 @@ +arr = input().split('-') +num = [] + +for i in arr: + if '+' in i: + sum = 0 + temp = i.split('+') + + for i in range(len(temp)): + sum += int(temp[i]) + else: + sum = i + + num.append(int(sum)) + +result = num[0] +if len(num) > 1: + for i in range(1,len(num)): + + result -= num[i] + +print(result) \ No newline at end of file