Travel with candy

Time Limit
1s
Memory Limit
262144KB
Judge Program
Standard
Ratio(Solve/Submit)
0.00%(0/1)
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 ai. 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 buyi and selli 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 N and C (N≤2×105,C≤106)
The second line contains N numbers a1,a2,...,an. It is guaranteed that ai>ai−1 for each 1<i<=N .
Next N+1 line : the i-th line contains two numbers buyi−1 and selli−1 respectively. (selli−1≤buyi−1≤106)

The sum of N in each test is less than 3×105.

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
Source:

2015 Multi-University Training Contest 8


Submit