#P10981. 任务安排 4.2

    ID: 19902 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DP平衡树单调队列cdq 分治斜率优化李超线段树

任务安排 4.2

Background

This problem is an enhanced version of P5785 and P10980.

Problem Description

There are nn tasks to be processed on a machine, forming a sequence. These tasks are numbered from 11 to nn, so the order of the sequence is 1,2,3,⋯ ,n1, 2, 3, \cdots, n. The 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 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 finish this batch is the sum of the times required by all tasks in the batch.

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

Determine a batching plan 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 a pair of integers TiT_i and CiC_i, meaning that the time required to complete task ii alone is TiT_i, and its cost coefficient is CiC_i.

Output Format

One line containing an 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, 1≤n≤3×1051 \le n \le 3 \times 10^5, 1≤s≤281 \le s \le 2^8, ∣Ti∣≤28|T_i| \le 2^8, ∣Ci∣≤28|C_i| \le 2^8.

Translated by ChatGPT 5