Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
HNPOSTMAN - Nhân viên bưu điện |
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 ≤ 10^7). Each of the next n lines contains two space-separated integers xi (|xi| ≤ 10^7) and mi (1 ≤ mi ≤ 10^7).Output
Print, on a single line, the minimum amount of time it will take to complete the mail delivery route.Example
Input:
4 10
-7 5
-2 3
5 7
9 5
Output:
42
Input:
7 1
9400000 10000000
9500000 10000000
9600000 10000000
9700000 10000000
9800000 10000000
9900000 10000000
10000000 10000000
Output:
1358000000000000
Được gửi lên bởi: | noname00.pas |
Ngày: | 2017-11-27 |
Thời gian chạy: | 0.100s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | C-CLANG C CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 JAVA PAS-FPC PYTHON PYTHON3 |
Nguồn bài: | Bài tập Ôn HN 01/2017 (Thầy Nguyễn Đức Nghĩa) |