Overtaking
문제
There is a one-lane, one-way road from Budapest Airport to Hotel Forrás. The road is kilometres long.
Over the IOI 2023 event, transfer buses traverse this road. Buses are numbered from to . Bus () is scheduled to leave the airport at the -th second of the event, and can travel kilometre in seconds. Bus is a reserve bus that can travel kilometre in seconds. The time when it will leave the airport has not yet been decided.
Overtaking is not allowed on the road in general, but the buses are allowed to overtake each other at sorting stations. There are () sorting stations, numbered from to , on different positions on the road. Sorting station () is located kilometres from the airport along the road. The sorting stations are sorted in increasing distance from the airport, that is, for each . The first sorting station is the airport and the last one is the hotel, that is, and .
Each bus travels at maximum speed unless it catches up to a slower bus travelling ahead of it on the road, in which case they get bunched and forced to travel at the speed of the slower bus, until they reach the next sorting station. There, the faster buses will overtake the slower buses.
Formally, for each and such that and , the time (in seconds) when bus arrives at sorting station is defined as follows. Let for each , and let . For each such that :
- Define the expected time of arrival (in seconds) of bus at sorting station , denoted by , as the time when bus would arrive at sorting station if it was travelling at full speed from the time it arrived at sorting station . That is, le
- for each , and
- .
- Bus arrives at sorting station at the *maximum* of the expected times of arrivals of bus and of every other bus that arrived at station earlier than bus . Formally, let be the maximum of and every for which and .
The IOI organizers want to schedule the reserve bus (bus ). Your task is to answer questions of the organizers, which are of the following form: given the time (in seconds) when the reserve bus is supposed to leave the airport, at what time would it arrive at the hotel?