9044: Nazrin the Greeeeeedy Mouse

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

There're nnn cheeses in the house. The iii-th cheese is between point iii and point i+1i+1i+1. The iii-th cheese's size is aia_iai and its weight is bib_ibi.
Nazrin is at point 111 in the beginning and wants to steal some cheeses. She has mmm chances to take the cheeses:
In the iii-th time, Nazrin brings a bag of size szisz_iszi. Since she's greedy, for i>1i>1i>1, szi≥szi−1sz_i\ge sz_{i-1}sziszi1 always holds. She can travel from point 111 and take some cheeses. She can only travel from point xxx to x+1x+1x+1, or backwards. If she wants to travel from point xxx to point x+1x+1x+1, she has to dig a hole on the xxx-th cheese or take it. She can't take a cheese with a hole on it. Of course, the sum of the cheeses' size she takes in the iii-th time can't be larger than szisz_iszi. After taking the cheeses, she needs to go back to point 111.
Please maximize the sum of the weights of taken cheeses and output it.

输入格式

The first line contains two integer nnn (1≤n≤2001\le n\le 2001n200) and mmm (1≤m≤1051\le m\le 10^51m105).
For the following nnn lines, the iii-th line contains two integers aia_iai (1≤ai≤2001\le a_i\le 2001ai200) and bib_ibi (1≤bi≤1051\le b_i\le 10^51bi105).
The next line contains mmm integers, the iii-th one is szisz_iszi (1≤szi≤2001\le sz_i\le 2001szi200). Notice that for i>1i>1i>1, szi≥szi−1sz_i\ge sz_{i-1}sziszi1.

输出格式

One integer, the maximum sum of the weights of taken cheeses.

输入样例 复制

5 3
2 10
2 5
1 22
3 7
6 8
1 3 7

输出样例 复制

44