baekjoon 20260210

This commit is contained in:
songyc macbook 2026-02-10 22:47:47 +09:00
parent 8a4ad949fa
commit 6b8a5a1308
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import sys
import heapq
input = sys.stdin.readline
jewels = []
bags = []
N, K = map(int, input().split())
for _ in range(N) :
m, v = map(int, input().split())
jewels.append((-v, m))
for _ in range(K) :
bags.append(int(input()))
jewels.sort(key = lambda x: (x[1], x[0]))
bags.sort()
pq = []
ans = 0
idx = 0
for bag in bags :
while idx < N and jewels[idx][1] <= bag :
heapq.heappush(pq, jewels[idx][0])
idx += 1
if pq :
cost = heapq.heappop(pq)
ans -= cost
print(ans)

View File

@ -0,0 +1,8 @@
ans = []
for _ in range(int(input())) :
temp = 0
for k in range(1, int(input())+1) :
temp += k*(k+1)*(k+2)
ans.append(temp//2)
print('\n'.join(list(map(str, ans))))