Skip to content

Commit 2e59bf3

Browse files
authored
찬민 백준숙제 (#100)
1 parent 59ec40f commit 2e59bf3

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

cmkim/BaekJoon/백준_1202.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1+
import heapq
2+
import sys
3+
input = sys.stdin.readline
14
n, k = map(int, input().split())
2-
jewel = [[0, 0] for _ in range(n)]
3-
bag = [0 for _ in range(k)]
5+
6+
jewel = []
7+
bags = []
8+
49
for i in range(n):
5-
jewel[i] = list(map(int, input().split()))
10+
w, v = map(int, input().split())
11+
heapq.heappush(jewel, (w, v))
612

713
for i in range(k):
8-
bag[i] = int(input())
14+
heapq.heappush(bags, int(input()))
15+
16+
result = 0
17+
selected = []
18+
for _ in range(k):
19+
bags_weight = heapq.heappop(bags)
20+
21+
while jewel and bags_weight >= jewel[0][0]:
22+
tmp = heapq.heappop(jewel)
23+
w, v = tmp[0], tmp[1]
24+
heapq.heappush(selected, -v)
25+
26+
if selected:
27+
result -= heapq.heappop(selected)
928

10-
print(jewel)
11-
print(bag)
29+
print(result)
30+
'''
31+
4 4
32+
1 100
33+
2 200
34+
13 300
35+
10 500
36+
14
37+
3
38+
12
39+
1
40+
'''

cmkim/BaekJoon/백준_1541.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
arr = input().split('-')
2+
num = []
3+
4+
for i in arr:
5+
if '+' in i:
6+
sum = 0
7+
temp = i.split('+')
8+
9+
for i in range(len(temp)):
10+
sum += int(temp[i])
11+
else:
12+
sum = i
13+
14+
num.append(int(sum))
15+
16+
result = num[0]
17+
if len(num) > 1:
18+
for i in range(1,len(num)):
19+
20+
result -= num[i]
21+
22+
print(result)

0 commit comments

Comments
 (0)