Home STD Contest Notification Clarification Problems Ranklist Status Print Sign Out

Packing

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 32    Accepted Submission(s): 6


Problem Description
Avin¡¯s warehouse has a packing line with m outlets. There are n goods in total, which aren¡¯t on the packing line. And the i-th good will be sent to the xi outlet at time ti . In each second, Avin can send at most one good from one outlet to the packing line. For outlet i, there is an associated buffer with size ai, and goods can be placed in the buffer. However, at the end of each second, if the number of goods b at the outlet is greater than ai , Avin has to pay the utilization fee b - ai . Since Avin wants to save money, he asks you to find a plan to send all the goods to the packing line with minimum utilization fee. In order to finish today¡¯s work, Avin must send all goods to the packing line. Goods arrived at time ti can be sent to the packing line immediately at time ti.
 

Input
The first line contains two integers n and m (1 ¡Ü n, m ¡Ü 1, 000, 000) . In the following n lines, each of which contains two numbers ti (1 ¡Ü ti ¡Ü 1, 000, 000) and xi (1 ¡Ü xi ¡Ü m). In the next following line, there are m integers containing ai (1 ¡Ü ai ¡Ü 1, 000, 000).
 

Output
Print the minimum utilization fee.
 

Sample Input
10 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2
 

Sample Output
21
 

Statistic | Submit | Clarifications | Back