#Q186. 「一本通 5.6 例 1」任务安排 1
「一本通 5.6 例 1」任务安排 1
Description
Original source: JoyOI TYVJ 1098
There are tasks arranged in a sequence waiting to be executed on a machine, and their order cannot be changed. The machine will divide these tasks into several batches, each containing a consecutive set of tasks. Starting from time , the tasks are processed in batches. The time required to execute the -th task is . Additionally, before each batch of tasks starts, the machine requires a startup time of , so the total time to execute a batch of tasks is the startup time plus the sum of the time required for each task in the batch.
After a task is executed, it waits briefly in the machine until all tasks in the batch are completed. That is, all tasks in the same batch will finish at the same time. The cost of each task is its completion time multiplied by a cost coefficient .
Please plan a grouping scheme for the machine to minimize the total cost.
Input Format
The first line contains . The second line contains .
The next lines each contain a pair of positive integers, and , indicating that the -th task requires time to complete and has a cost coefficient .
Output Format
A single number, the minimum total cost.
Sample 1
The grouping scheme is . The completion times are , and the costs , resulting in a total cost of .
5
1
1 3
3 2
4 3
2 3
1 4
153
Data Range and Hints
For all data, .