PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000135. Giao thư trên trục số (Postal Delivery)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giao thư trên trục số (Postal Delivery)
Postal Delivery
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A post office is at coordinate . Address lies at nonzero coordinate and needs letters. The truck carries at most letters per trip, must start each trip at and return to , and may visit multiple addresses along a trip. Find the minimum total travel distance.
Input
The first line has . The next lines contain in strictly increasing order.
Output
Print the minimum total round-trip travel distance.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
3 100
-10 50
10 175
25 20
Output
90
Explanation
One round trip to costs . On the positive side, a trip to delivers letters ( distance); another goes to , delivers there and the remaining at ( distance). Total .