QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#4140. Task Scheduling

الإحصائيات

There are $n$ tasks to be processed on a machine, forming a sequence. These tasks are labeled $1$ to $n$, so the sequence is $1, 2, 3, \dots, n$. The $n$ tasks are divided into several batches, where each batch consists of a contiguous sequence of tasks. Starting from time $0$, these tasks are processed in batches. The time required to complete the $i$-th task individually is $T_i$. Before each batch of tasks begins, the machine requires a setup time $s$, and the time required to complete a batch is the sum of the times required for each task in that batch.

Note that all tasks in the same batch are completed at the same time. The cost for each task is its completion time multiplied by a cost coefficient $C_i$.

Please determine a grouping scheme that minimizes the total cost.

Input

The first line contains an integer $n$.

The second line contains an integer $s$.

The next $n$ lines each contain a pair of integers, $T_i$ and $C_i$, representing the time required to complete the $i$-th task individually and its cost coefficient $C_i$, respectively.

Output

A single integer representing the minimum total cost.

Examples

Input 1

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

Output 1

153

Subtasks

For $100\%$ of the data, $1 \le n \le 3 \times 10^5$, $1 \le s \le 2^8$, $\left| T_i \right| \le 2^8$, $0 \le C_i \le 2^8$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.