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