Christmas Eve

Given n weighted warehouses on a line, choose k of them as teleporter sites so that moving every other warehouse's presents into a chosen site gives the least total weighted distance.

Medium7Dynamic programmingSortingDivide and conquerPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Santa Corporation delivers presents to children all over the world between Christmas Eve night and Christmas morning. Every santa who volunteers for delivery receives one high tech sleigh, and the trunk of that sleigh is connected by a teleporter to a single warehouse of the supply department. A warehouse holds at most one teleporter, so each sleigh needs its own warehouse.

The supply department manages nn warehouses placed on a straight line. You must pick kk of them for the teleporters and move all presents from the remaining warehouses into the chosen ones.

Warehouse ii sits at position xix_i and holds wiw_i tons of presents. The presents of one warehouse cannot be split, so they all move at once into one other warehouse. Moving ww tons from the warehouse at xix_i to the warehouse at xjx_j costs xixj×w|x_i - x_j| \times w.

Santa Corporation wants to spend as little as possible. Pick the kk warehouses so that the total moving cost is minimum, and report that cost.

Input

The first line has the number of warehouses nn and the number of teleporters kk (1k<n50001 \le k < n \le 5000).

Each of the next nn lines has the position xix_i of warehouse ii and the weight wiw_i of the presents stored there (1xi,wi10000001 \le x_i, w_i \le 1000000).

The warehouses are not given in position order, and several warehouses can share one position.

Output

Print the minimum total cost of moving every present into the kk chosen warehouses.