F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Travel with candy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 518    Accepted Submission(s): 253


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 $a_i$. 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 $buy_i$ and $sell_i$ 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 \leq 2\times 10^5, C\leq 10^6)$
The second line contains $N$ numbers $a_1,a_2,...,a_n$. It is guaranteed that $a_i>a_{i-1}$ for each $ 1< i<=N$ .
Next $N+1$ line : the i-th line contains two numbers $buy_{i-1}$ and $sell_{i-1}$ respectively. ($sell_{i-1} \leq buy_{i-1} \leq 10^6$)

The sum of $N$ in each test is less than $3\times 10^5$.
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:50:59, Gzip enabled