#P6538. [COCI 2013/2014 #1] LOPOV

[COCI 2013/2014 #1] LOPOV

Background

There are some items and a thief.

Problem Description

There are NN items. Each item has a weight MiM_i and a value ViV_i.

Mirko has KK bags. The maximum weight each bag can hold is CiC_i.

Each bag can contain only one item. What is the maximum total value of items that can be taken?

Input Format

The first line contains two positive integers NN and KK.

Each of the next NN lines contains two positive integers MiM_i and ViV_i.

Each of the next KK lines contains one positive integer CiC_i.

Output Format

Output one line: the maximum total value of the items that can be taken.

2 1
5 10
100 100
11 
10
3 2
1 65
5 23
2 99
10
2
164

Hint

Constraints

  • 1N,K3×1051 \le N, K \le 3 \times 10^5.
  • 1Mi,Vi1061 \le M_i, V_i \le 10^6.
  • 1Ci1081 \le C_i \le 10^8.

Explanation for Sample 2

Mirko puts the first item into the second bag, and the third item into the first bag.

Notes

This problem is translated from COCI2013-2014 CONTEST #1 T4 LOPOV.

Translated by ChatGPT 5