Time limit
1s
Memory limit
256 MB
A thief plans to steal jewels from a jewelry store.
The store has N jewels. The i-th jewel has weight M_i and value V_i. The thief has K bags, and the j-th bag can hold a jewel whose weight is at most C_j.
Each bag can contain at most one jewel, and each jewel can be stolen at most once. Find the maximum possible total value of the stolen jewels.
The first line contains the number of jewels N and the number of bags K. (1 <= N, K <= 300,000)
Each of the next N lines contains the weight M_i and value V_i of one jewel. (0 <= M_i, V_i <= 1,000,000)
Each of the next K lines contains the maximum weight C_j that one bag can hold. (1 <= C_j <= 100,000,000)
All values in the input are integers.
Print the maximum possible total value of the stolen jewels.
In the second public test, putting the first jewel into the second bag and the third jewel into the first bag gives a total value of 164.