Problem list
Log in
#coci00273 · COCI 2013/2014 Contest 1

Lopov

Gold II 1.0 s 32 MB

The difficult economic situation in the country and reductions in government agricultural subsidy funding have caused Mirko to change his career again, this time to a thief. His first professional endeavour is a jewellery store heist. The store contains N pieces of jewellery, and each piece has some mass M_{i} and value V_{i}. Mirko has K bags to store his loot, and each bag can hold some maximum mass C_{i}. He plans to store all his loot in these bags, but at most one jewellery piece in each bag, in order to reduce the likelihood of damage during the escape. Find the maximum total jewellery value that Mirko can “liberate”.

Input

The first line of input contains two numbers, N and K ($1 \le N$, $K \le 300,000$). Each of the following N lines contains a pair of numbers, M_{i} and V_{i} ($1 \le M_{i}$, $V_{i} \le 1,000,000$). Each of the following K lines contains a number, C_{i} ($1 \le C_{i} \le 100,000,000$). All numbers in the input are positive integers.

Output

The first and only line of output must contain the maximum possible total jewellery value.

Constraints

In test data worth at least 50% of total points, N and K will be less than 5000.

Example 1

Input
2 1
5 10
100 100
11
Output
10

Example 2

Input
3 2
1 65
5 23
2 99
10
2
Output
164

Clarification of the second example: Mirko stores the first piece of jewellery into the second bag and the third piece into the first bag.

Source
COCI 2013/2014 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code