#P2365. 任务安排

任务安排

Description

There are nn tasks arranged in a sequence waiting to be completed on a single machine (the order cannot be changed). These nn tasks are divided into several batches, each batch containing consecutive tasks.

Starting from time 00, the tasks are processed batch by batch. The time required to complete task ii alone is tit_i. Before each batch starts, the machine needs a startup time ss, and the time required to process that batch is the sum of the required times of its tasks (all tasks in the same batch finish at the same time).

The cost of each task is its completion time multiplied by a cost coefficient fif_i. Determine a batching scheme that minimizes the total cost.

Input Format

The first line contains a positive integer nn.
The second line contains an integer ss.
Each of the next nn lines contains a pair of numbers, tit_i and fif_i, indicating that the time required to complete task ii alone is tit_i and its cost coefficient is fif_i.

Output Format

Output a single number, the minimal total cost.

5
1
1 3
3 2
4 3
2 3
1 4
153

Hint

Constraints
For 100%100\% of the testdata, 1n50001 \le n \le 5000, 0s500 \le s \le 50, 1ti,fi1001 \le t_i, f_i \le 100.

Sample explanation
If the batching scheme is {1,2},{3},{4,5}\{1,2\}, \{3\}, \{4,5\}, then the completion times are {5,5,10,14,14}\{5, 5, 10, 14, 14\}, the cost is C=15+10+30+42+56C=15+10+30+42+56, so the total cost is 153153.

Translated by ChatGPT 5