#GL0000311. Các trạm xe buýt (Bus Stops)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các trạm xe buýt (Bus Stops)
Bus Stops
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi wants to visit Aoki by walking and taking buses. There are bus stops numbered from through along the route.
Walking from Takahashi's house to stop takes units of time. For every , buses depart from stop for stop at every time that is a multiple of , and the trip takes units of time. After reaching stop , walking to Aoki's house takes another units of time.
Takahashi may board a bus even when he arrives at the stop exactly at its departure time. He may wait at stops, but wishes to arrive as early as possible.
You are given departure times . For each departure time, determine the earliest possible arrival time at Aoki's house.
Input
- The first line contains three integers .
- The next lines each contain , the departure interval and travel time between stops and .
- The next line contains .
- Each of the following lines contains one departure time .
Output
Print lines, where line is the earliest arrival time when departing at .
Subtasks
- Subtask 0 (20 points): ; ; ; and for all ; for all .
- Subtask 1 (30 points): ; ; ; and for all ; for all .
- Subtask 2 (50 points): ; ; ; and for all ; for all .
Examples
Example 1
Input
4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230
Output
34
22
710511052
136397548
763027402
644706946
447672250
Explanation
For , he walks to stop 1 at time , takes a bus to stop 2 arriving at , waits until for the next leg, reaches stop 3 at , boards immediately and reaches stop 4 at , then walks for units, arriving at . For , he reaches stop 1 at , boards buses at , , and , and arrives at . The remaining five lines correspond to the other five departure times.