PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000020. Đường đi giữa các khách sạn (Tak and Hotels)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường đi giữa các khách sạn (Tak and Hotels)
Tak and Hotels
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are hotels at distinct positions along a straight road. On each day Tak may travel from his current hotel to another hotel at distance at most and stay there overnight.
For every query , find the minimum number of days required to travel from hotel to hotel . Adjacent hotels are at most apart, so every trip is feasible.
Travel is permitted in either direction.
Input
- The first line contains .
- The second line contains hotel positions .
- The next line contains .
- The following line contains .
- The last lines contain hotel indices .
Output
Print the minimum number of days for each trip, one line per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
Output
4
2
1
2
Explanation
With , travel from hotel to along takes days. Going from hotel to takes just day.