import sys
import heapq

input = sys.stdin.readline


N, K = map(int,input().split())

visited = [False]*K
jewel = []
for _ in range(N):
    m,v = map(int,input().split())
    heapq.heappush(jewel,(m,v))

bags = []
for _ in range(K):
    bags.append(int(input()))

bags.sort()
result = 0
possible_jewel = []
for bag in bags:
    while jewel and jewel[0][0] <= bag:
        m,v = heapq.heappop(jewel)
        heapq.heappush(possible_jewel,-v)
    
    if possible_jewel:
        result -= heapq.heappop(possible_jewel)
        
    

print(result)

 

N, M = map(int,input().split())
total_length = N*M
so_list = [M]*N

cnt = 0
for k in range(N):
    if so_list[k]%N:
        cnt += so_list[k]//N
    else:
        cnt = cnt + so_list[k]//N-1
    so_list[k] -= so_list[k]//N*N

if sum(so_list):
    ind = 0
    temp = 0
    while ind <N:
        temp += so_list[ind]
        if temp == N:
            temp = 0
        elif temp >N:
            cnt += 1
            temp -= N
        ind += 1
        
print(cnt)

 

 

import functools
n,m = map(int,input().split())
@functools.lru_cache()
def gdc(n,m):
    if not n%m:
        return m
    return gdc(m,n%m)

print(m-gdc(n,m))

+ Recent posts