Ever since Krešo started growing chili peppers,
The restaurants are denoted with numbers from
Since delivering goods is tiring, Krešo decided to spend a total of
Determine the maximal amount of peppers Krešo can deliver in the given timeframe. You can assume that Krešo always carries an unlimited supply of peppers.
Input Specification
The first line of input contains two integers
The second line of input contains
Each of the following
Output Specification
You must output the maximal amount of peppers Krešo can deliver in the given timeframe.
Sample Input 1
3 5
9 2 5
1 2
1 3
Sample Output 1
14
Explanation for Sample Output 1
In the first step, Krešo will deliver the peppers to restaurant 1.
In the second step, Krešo will travel to restaurant 3.
In the third step, Krešo will deliver the peppers to restaurant 3.
He is left with 2 units of time, in which he can drive to restaurant 2, but he lacks one unit of time to deliver the peppers to that restaurant.
Sample Input 2
4 5
1 1 1 2
1 2
2 3
3 4
Sample Output 2
3
Sample Input 3
5 10
1 3 5 2 4
5 2
3 1
2 3
4 2
Sample Output 3
15
Comments