This page is still under construction.

Parts of this page are still being built. What you see may change.

Batch Scheduling

Time limit1sMemory limit128 MB

Summary
Split the ordered jobs into consecutive batches, each paying a setup time, and minimize the sum of weighted completion times.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum, Greedy
Solved
No attempts yet

Problem

A single machine processes NN jobs numbered 11 through NN in order. The job sequence 1,2,…,N1, 2, \dots, N must be split into one or more batches, where each batch is a group of consecutive jobs.

Processing starts at time 00. The batches are handled one at a time starting from the first, and a batch containing lower-numbered jobs is handled before one containing higher-numbered jobs. Before each batch, the machine needs a setup time SS.

If a batch consists of jobs x,x+1,…,x+kx, x+1, \dots, x+k and starts at time tt, then the output (completion) time of every job in that batch is t+S+(Tx+Tx+1+⋯+Tx+k).t + S + (T_x + T_{x+1} + \dots + T_{x+k}). The machine outputs all results of a batch at the same time, and the next batch starts immediately afterward.

Each job ii has a processing time TiT_i and a cost factor FiF_i. If the output time of job ii is OiO_i, its cost is Oi×FiO_i \times F_i. The total cost of a partition is the sum of the costs of all jobs.

Given the setup time together with each job's processing time and cost factor, write a program that computes the minimum possible total cost.

Input

The first line contains the number of jobs NN (1≤N≤100001 \le N \le 10000).

The second line contains the setup time SS as an integer (0≤S≤500 \le S \le 50).

Each of the next NN lines describes jobs 1,2,…,N1, 2, \dots, N in order. Each line contains two integers TiT_i and FiF_i, where TiT_i is the processing time of the job (1≤Ti≤1001 \le T_i \le 100) and FiF_i is its cost factor (1≤Fi≤1001 \le F_i \le 100).

Output

Print the minimum possible total cost as a single integer on one line.

Note

For every test case, the total cost of any partition does not exceed 231−12^{31} - 1.

Examples2

  1. Example 1

    Input
    2
    50
    100 100
    100 100
    
    Expected output
    45000
    
  2. Example 2

    Input
    5
    1
    1 3
    3 2
    4 3
    2 3
    1 4
    
    Expected output
    153