#P5769. [JSOI2016] 飞机调度
[JSOI2016] 飞机调度
Description
In the JSOI Kingdom, there are airports, numbered from to . Flying from airport to airport takes time . Due to wind direction, geographic location, and air traffic control, and are not necessarily the same.
Also, after an aircraft lands, it needs routine maintenance and refueling. When an aircraft lands at airport , it must spend time on maintenance before it can take off again.
JS Airways operates a total of routes. For the -th direct flight, it must take off from airport at time and fly non-stop to airport .
To simplify the problem, we assume JS Airways can place any number of fully maintained and refueled aircraft at any airport at time . To reduce the number of aircraft used, we also allow JS Airways to add any number of temporary flights to satisfy scheduling needs.
JYY wants to know: in theory, what is the minimum number of aircraft JS Airways needs to complete all these flights.
Input Format
The first line contains two positive integers .
The next line contains positive integers, representing the aircraft maintenance time for each airport.
The next lines each contain non-negative integers. The -th non-negative integer in the -th line is , meaning the time required to fly from airport to airport . The data guarantees .
The next lines each contain three positive integers. The -th line is , representing the departure airport, the arrival airport, and the departure time of the -th route. The data guarantees .
Output Format
Output one positive integer in a single line, representing the theoretical minimum number of aircraft JS Airways needs.
3 3
100 1 1
0 1 1
1 0 5
2 1 0
1 2 1
2 1 1
3 1 9
2
3 3
100 1 1
0 1 1
1 0 5
2 1 0
1 2 1
2 1 1
3 1 8
3
Hint
Sample Explanation 1
In the first sample, JS Airways can arrange one aircraft at airport at time and use it to operate flight (). In addition, it needs to arrange one aircraft at airport at time . This aircraft first operates flight (), then takes a newly added temporary flight from airport to airport , and after landing at airport , it operates flight ().
Sample Explanation 2
In the second sample, the aircraft that finishes flight cannot catch the departure time of flight . Therefore, JS Airways must use different aircraft to complete all flights.
Constraints
For of the testdata, .
For of the testdata, .
For all testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号