#P11118. [ROI 2024] 无人机比赛 (Day 2)
[ROI 2024] 无人机比赛 (Day 2)
Background
Translated from ROI 2024 D2T3.
There are drones registered to participate in a drone race. The -th drone needs seconds to fly one unit of distance.
The race is held on a straight line with gates, numbered from to . The -th gate is located at distance from the start of the race.
Due to the limited size of the track, only the first drones will participate in the first race, numbered from to . The value of will be announced by the judges before the race starts, so you need to analyze the race outcome for all from to .
The race proceeds as follows:
The drones move from point toward the gates, and each drone has a different speed. Each drone has a checkpoint, which is the last gate where it performed a save operation. Initially, every drone’s checkpoint is point .
During the race, all drones start moving from their checkpoints, until one or more drones reach a gate (it is possible that different drones reach different gates at the same time). At that moment, among all drones that have reached a gate, choose the drone with the smallest index and perform a save operation for it, setting its checkpoint to the current position. All other drones are immediately teleported back to their checkpoints. Then the race continues.
If a drone performs a save operation at the last gate, numbered , then it finishes the race. The drones that have not yet finished will be teleported back to their checkpoints and continue racing. When all drones finish, the race ends.
Problem Description
Teleportation is a very energy-consuming process. To prepare for the race, you need to know how many times in total all drones will teleport before the race ends. Let denote the total number of teleports made by all drones when the first drones participate in the race. You need to compute .
Input Format
The first line contains two integers and , representing the number of drones and the number of gates, respectively (,).
The second line contains positive integers , where is the number of seconds the -th drone needs to fly one unit of distance ().
The third line contains positive integers , where is the position of the -th gate ().
Output Format
Output integers , as described above.
3 3
1 2 3
1 3 6
0
4
11
3 3
3 2 1
1 3 6
0
5
13
2 5
2 1
1 3 4 6 7
0
6
Hint
Sample explanation:
When , no teleportation is needed, because only one drone participates, and only it keeps saving all the time.
When , the whole race process is shown in the figure below.

When , the whole race process is shown in the figure below.

Special properties table for subtasks:
| Subtask | Score | Other special properties | ||||
|---|---|---|---|---|---|---|
| All are equal | ||||||
Translated by ChatGPT 5