Batch Scheduling#4144

Batch Scheduling

0.1 seconds
256 megabytes
Very easy

There is a sequence of jobs to be processed on one machine. The jobs are numbered from to , so the sequence is 1, 2, \ldots, N. The sequence of jobs must be partitioned into one or more batches, where each batch consists of consecutive jobs in the sequence.

The processing starts at time . The batches are handled one by one starting from the first batch as follows. If a batch contains jobs with smaller numbers than batch , then batch is handled before batch . The jobs in a batch are processed successively on the machine. Immediately after all the jobs in a batch are processed, the machine outputs the results of all the jobs in that batch. The output time of a job is the time when the batch containing finishes.

A setup time is needed to set up the machine for each batch. For each job , we know its cost factor F_i and the time T_i required to process it. If a batch contains the jobs x, x+1, \ldots, x+k, and starts at time , then the output time of every job in that batch is

t + S + (T_x + T_{x+1} + \ldots + T_{x+k})

Note that the machine outputs the results of all jobs in a batch at the same time. If the output time of job is O_i, its cost is O_i \times F_i.

For example, assume there are jobs, the setup time is S = 1, (T_1, T_2, T_3, T_4, T_5) = (1, 3, 4, 2, 1), and (F_1, F_2, F_3, F_4, F_5) = (3, 2, 3, 3, 4).

If the jobs are partitioned into three batches \{1, 2\}, \{3\}, \{4, 5\}, then the output times are (O_1, O_2, O_3, O_4, O_5) = (5, 5, 10, 14, 14) and the costs of the jobs are (15, 10, 30, 42, 56), respectively. The total cost for a partitioning is the sum of the costs of all jobs. The total cost for the example partitioning above is .

You are to write a program which, given the batch setup time and a sequence of jobs with their processing times and cost factors, computes the minimum possible total cost.

Input

Your program reads from standard input.

  • The first line contains the number of jobs , 1 \leq N \leq 10000.

  • The second line contains the batch setup time (0 \leq S \leq 50).

  • The following lines each contain information about jobs 1, 2, \ldots, N in that order. Each of these lines contains:

    • An integer T_i (1 \leq T_i \leq 100), the processing time of the job.

    • An integer F_i (1 \leq F_i \leq 100), the cost factor of the job.

Output

Your program must output to standard output one line containing a single integer: the minimum possible total cost.

Examples

Example 1

Loading
Loading