#P1315. [NOIP 2011 提高组] 观光公交

[NOIP 2011 提高组] 观光公交

Description

In the scenic city Y, there are nn beautiful spots. As more tourists arrive, the city arranges a sightseeing bus to offer convenient transportation. The bus appears at spot 11 at minute 00, and then visits spots 2,3,4,,n2, 3, 4, \cdots, n in order. It takes DiD_i minutes to go from spot ii to spot i+1i+1. At any time, the bus can only move forward, or wait at a spot.

There are mm passengers in total. Each passenger needs exactly one ride from one spot to another. The ii-th passenger arrives at spot AiA_i at minute TiT_i and wants to ride to spot BiB_i (Ai<BiA_i < B_i). 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 kk nitro boosters. Each booster can decrease some DiD_i by 11. You may apply boosters multiple times to the same DiD_i, but must ensure that after all applications Di0D_i \ge 0.

How should ZZ allocate the boosters to minimize the sum of all passengers’ travel times?

Input Format

  • The first line contains 33 integers n,m,kn, m, k, separated by single spaces, denoting the number of spots, the number of passengers, and the number of boosters.
  • The second line contains n1n-1 integers, separated by single spaces. The ii-th integer is the travel time DiD_i from spot ii to spot i+1i+1.
  • Lines 33 to m+2m+2: each line contains 33 integers Ti,Ai,BiT_i, A_i, B_i, separated by single spaces. The (i+2)(i+2)-th line gives the arrival time at the origin, the origin spot index, and the destination spot index for passenger ii.

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 22 boosters on D2D_2, reducing the travel time from spot 22 to spot 33 to 22 minutes.

The bus departs from spot 11 at minute 11, arrives at spot 22 at minute 22, departs from spot 22 at minute 55, and arrives at spot 33 at minute 77.

  • Passenger 11: travel time ==\, 70=77-0=7 minutes.
  • Passenger 22: travel time ==\, 21=12-1=1 minute.
  • Passenger 33: travel time ==\, 75=27-5=2 minutes.

Total time ==\, 7+1+2=107+1+2=10 minutes.

【Constraints】

  • For 10%10\% of the testdata, k=0k=0.
  • For 20%20\% of the testdata, k=1k=1.
  • For 40%40\% of the testdata, 2n502 \le n \le 50, 1m1031 \le m \le 10^3, 0k200 \le k \le 20, 0Di100 \le D_i \le 10, 0Ti5000 \le T_i \le 500.
  • For 60%60\% of the testdata, 1n1001 \le n \le 100, 1m1031 \le m \le 10^3, 0k1000 \le k \le 100, 0Di1000 \le D_i \le 100, 0Ti1040 \le T_i \le 10^4.
  • For 100%100\% of the testdata, 1n1031 \le n \le 10^3, 1m1041 \le m \le 10^4, 0k1050 \le k \le 10^5, 0Di1000 \le D_i \le 100, 0Ti1050 \le T_i \le 10^5.

Translated by ChatGPT 5