#P10979. 任务安排 2

任务安排 2

Background

This problem is an enhanced version of P2365 and a simplified version of P5785. It is used to help students gradually understand slope-optimized DP.

Problem Description

There are nn tasks to be processed on a machine, forming a sequence. The tasks are numbered from 11 to nn, so the order is 1,2,3n1, 2, 3 \cdots n. These nn tasks are divided into several batches, and each batch contains several adjacent tasks. Starting from time 00, the tasks are processed batch by batch. The time needed to finish task ii alone is TiT_i. Before starting each batch, the machine needs a startup time ss, and the time to finish this batch is the sum of the times of all tasks in it.

Note that tasks in the same batch will be completed at the same time. The cost of each task equals its completion time multiplied by a cost coefficient CiC_i.

Please determine a batching scheme that minimizes the total cost.

Input Format

The first line contains an integer nn. The second line contains an integer ss.

The next nn lines each contain two integers TiT_i and CiC_i, meaning that the time needed to finish task ii alone is TiT_i, and its cost coefficient is CiC_i.

Output Format

One line with one integer, representing the minimum total cost.

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

Hint

For 100%100\% of the testdata, 1n3×1051 \le n \le 3 \times 10^5, 1s281 \le s \le 2^8, 1Ti281 \le T_i \le 2^8, 0Ci280 \le C_i \le 2^8.

Translated by ChatGPT 5