Postman

TimeLimit:1000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

A postman delivers letters to his neighbors in a one-dimensional world.

The post office, which contains all of the letters to begin with, is located at x = 0, and there are n houses to which the postman needs to deliver the letters. House i is located at position xi , and there are mi letters that need to be delivered to this location. But the postman can only carry k letters at once.

The postman must start at the post office, pick up some number of letters less than or equal to his carrying capacity, and then travel to some of the houses dropping off letters. He must then return to the post office, repeating this process until all letters are delivered. At the end he must return to the post office.

The postman can travel one unit of distance in one unit of time.

What is the minimum amount of time it will take the postman to start at the post office, deliver all the letters, and return to the post office?

Input

The first line of input contains two space-separated integers n (1 ≤ n ≤ 1,000) and k (1 ≤ k ≤ 107). Each of the next n lines contains two space-separated integers xi (|xi| ≤ 107) and mi (1 ≤ mi ≤ 107).

Output

Print, on a single line, the minimum amount of time it will take to complete the mail delivery route.

SampleInput 1
4 10
-7 5
-2 3
5 7
9 5
SampleOutput 1
42
SampleInput 2
7 1
9400000 10000000
9500000 10000000
9600000 10000000
9700000 10000000
9800000 10000000
9900000 10000000
10000000 10000000
SampleOutput 2
1358000000000000
Submit
题目统计信息详细
总AC数1
通过人数1
尝试人数2
总提交量2
AC率50.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: