Problem Description
Description
The weather is too hot, so 985 made a plan for the future: on day i he will drink a[i] bottles of beverage. To save expenses, he found out the price p[i] per bottle on day i.
To keep his plan from falling through, he wants to know the minimum amount he must spend over these n days.
The shrewd 985 can choose to buy any number of beverages on any day, and he has a magic refrigerator that can preserve beverages bought in advance (at least they are drinkable during these n days).
Input
The first line contains an integer t, representing t test cases.
For each test case, the first line contains an integer n, the total number of planned days, followed by n lines, each containing two integers a[] and p[], which represent the information mentioned above.
Note: 1 <= t <= 30, 1 <= n <= 1000, 1 <= a[], p[] <= 100.
Output
Output an integer representing the final result.
Sample Input
| |
Sample Output
| |
Problem Analysis
The optimal unit price for buying on day i is min(p[j]) (1 <= j <= i)
so a single scan is enough.
| |
Problem link: ZZULI [1896] 985’s Beverage Purchasing Problem