#P10977. [2015杭电多校]Travel with candy
[2015杭电多校]Travel with candy
Travel with candy
Problem Description
There are n+1 cities on a line. They are labeled from city 0 to city n. Mph has to start his travel from city 0, passing city 1,2,3...n-1 in order and finally arrive city n. The distance between city i and city 0 is . Mph loves candies and when he travels one unit of distance, he should eat one unit of candy. Luckily, there are candy shops in the city and there are infinite candies in these shops. The price of buying and selling candies in city i is and per unit respectively. Mph can carry at most C unit of candies. Now, Mph want you to calculate the minimum cost in his travel plan.
Input
There are multiple test cases. The first line has a number T, representing the number of test cases. For each test : The first line contains two numbers and The second line contains numbers . It is guaranteed that for each . Next line : the i-th line contains two numbers and respectively. () The sum of in each test is less than .
Output
Each test case outputs a single number representing your answer.(Note: the answer can be a negative number)
Sample Input
1
4 9
6 7 13 18
10 7
8 4
3 2
5 4
5 4
Sample Output
105
Author
SXYZ
Source
2015 Multi-University Training Contest 8