import sys
input = sys.stdin.readline
# ๋ฐฐ๋ญ ๋ฌด๊ฒ ์ ํ W , n์ข
๋ฅ์ ๊ท๊ธ์
# ๊ฐ์ฅ ๋์ ๊ฐ๊ฒฉ์ผ๋ก ๋ฐฐ๋ญ ์ฑ์ฐ๊ธฐ
w,n = map(int,input().split())
total_price = 0
#๋ฆฌ์คํธ ์ปดํ๋ฆฌํจ์
arr = [list(map(int,input().split())) for _ in range(n)]
arr.sort(key = lambda x:x[1],reverse=True)
idx = 0
while w>0:
if arr[idx][0] >= w:
total_price += arr[idx][1]*w
break
else:
total_price += arr[idx][0]*arr[idx][1]
w -= arr[idx][0]
idx += 1
print(total_price)
์ฒ์์ ํ๋๋ ๋ฆฌ์คํธ๋ฅผ ์์ฑํด๋๊ณ
์ ๋ ฅ๊ฐ์ append ํ์๋๋ฐ ์๊ฐ์ด๊ณผ๊ฐ ๊ณ์ ๋์๋ค.
for _ in range(n):
a,b = map(int,input().split())
arr.append((b,a)) # b ๋ฌด๊ฒ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
List Comprehension์ ์๋๊ฐ ๋น ๋ฅธ์ด์
'Algorithm > Softeer' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Softeer - level2] ๋ฐ์ด๋ฌ์ค (0) | 2023.07.25 |
---|---|
[Softeer - level2] ์ง๋ ์๋ ๊ตฌ์ถ (0) | 2023.07.25 |
[Softeer - level2] 8๋จ ๋ณ์๊ธฐ (0) | 2023.07.25 |
[Softeer - level3] ์ค๋งํธ ๋ฌผ๋ฅ (0) | 2023.07.24 |
[Softeer - level3] ํ๋ฐฐ ๋ง์คํฐ ๊ด์ฐ (0) | 2023.07.24 |