Task
Adrian is starting a new business as a travel counsellor, helping tourists to plan their trip along the Amazon River!
Along the river, there are boat excursions available, the -th of which starting at meters from the river source and ending at meters from the river source.
All excursions follow the water flow, in order to keep the engines turned off and ensure a full immersion in the natural environment.
Tourists are often puzzled by the huge number of available options. So, they call Adrian for suggestions! There are requests from tourists. The -th request comes from
a tourist standing at meters from the river source. That tourist wants to plan a series of trips that brings him to the farthest possible distance from the river source,
using a tourist pass that allows to do at most excursions. Furthermore, the tourist wants to do at least excursions,
and does not want to repeat an excursion.
The chosen excursions must be perfectly consecutive: each of them must start where the previous one has ended, with the first one starting at and the last one ending in .
In case it is impossible to plan a series of at least excursions, we conventionally set to . Help Adrian answer the tourists' requests!
Input data
The input file consists of:
- a line containing integer .
- lines, the -th of which consisting of 64-bit integers , .
- a line containing integer .
- lines, the -th of which consisting of 64-bit integer and integers , .
Output data
The output file must contain a single line consisting of the integers .
Constraints and clarifications
- .
- .
- .
- .
- .
# | Score | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 20 | , . |
3 | 20 | for each . |
4 | 20 | for each . |
5 | 20 | . |
6 | 20 | No additional limitations. |
Example 1
stdin
5
0 2
0 4
2 5
4 10
5 6
3
0 0 3
0 3 3
2 1 5
stdout
10 6 6
Explanation
In the first sample case, the available excursions are as follows:
The first tourist stands at , and wants to perform a number of excursions from to . The farthest he can reach is through the two excursions , thus .
The second tourist also stands at , but wants to perform exactly excursions: his only option is the trip .
The last tourist stands at , and wants to perform a number of excursions between and . His best option is the trip .
Example 2
stdin
5
4 4
2 4
4 4
4 7
2 4
4
2 4 4
2 5 5
1 0 2
1 1 5
stdout
7 -1 1 -1
Explanation
In the second sample case, the available excursions are as follows:
The first tourist stands at , and wants to perform exactly excursions: his only option is the trip .
The second tourist also stands at , but wants to perform exactly excursions: this is not possible, so the answer is .
The third tourist stands at , and wants to perform a number of excursions from to . His only possibility is to perform excursions, staying at , since there are no excursions starting from .
The last tourist also stands at , but wants to perform at least one excursion, which is not possible, so the answer is .