#P1315. [NOIP 2011 提高组] 观光公交
[NOIP 2011 提高组] 观光公交
Description
In the scenic city Y, there are beautiful spots. As more tourists arrive, the city arranges a sightseeing bus to offer convenient transportation. The bus appears at spot at minute , and then visits spots in order. It takes minutes to go from spot to spot . At any time, the bus can only move forward, or wait at a spot.
There are passengers in total. Each passenger needs exactly one ride from one spot to another. The -th passenger arrives at spot at minute and wants to ride to spot (). To ensure that all passengers can reach their destinations, the bus must, at each spot, wait until all passengers who need to depart from that spot have boarded, and then depart for the next spot.
Assume boarding and alighting take no time. A passenger’s travel time equals the time they reach their destination minus the time they arrive at their origin. Because there is only one bus and it sometimes needs to wait for other passengers, passengers complain that the travel time is too long. The clever driver ZZ installs nitro boosters. Each booster can decrease some by . You may apply boosters multiple times to the same , but must ensure that after all applications .
How should ZZ allocate the boosters to minimize the sum of all passengers’ travel times?
Input Format
- The first line contains integers , separated by single spaces, denoting the number of spots, the number of passengers, and the number of boosters.
- The second line contains integers, separated by single spaces. The -th integer is the travel time from spot to spot .
- Lines to : each line contains integers , separated by single spaces. The -th line gives the arrival time at the origin, the origin spot index, and the destination spot index for passenger .
Output Format
Output a single integer: the minimal possible total travel time.
3 3 2
1 4
0 1 3
1 1 2
5 2 3
10
Hint
【Sample Explanation】
Use boosters on , reducing the travel time from spot to spot to minutes.
The bus departs from spot at minute , arrives at spot at minute , departs from spot at minute , and arrives at spot at minute .
- Passenger : travel time minutes.
- Passenger : travel time minute.
- Passenger : travel time minutes.
Total time minutes.
【Constraints】
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , , , .
- For of the testdata, , , , , .
- For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号