#P6772. [NOI2020] 美食家
[NOI2020] 美食家
Problem Description
After the Elf Kingdom on the continent of Bzeroth repelled the invasion of the Catastrophe Legion, it spent more than ten years recovering and once again became a thriving paradise that attracts visitors from all directions. Little W is a famous gourmet who has traveled around the world, and he has now come to the Elf Kingdom by reputation.
The Elf Kingdom has cities, numbered from to . The food in city can provide Little W with happiness. The cities are connected by directed roads, numbered from to . For road , its start city is , its end city is , and traveling along it takes days. That is, if Little W travels from city along road on day , then he will arrive at city on day .
Little W plans a trip in the Elf Kingdom lasting days. More specifically: he will set off from city on day , and after days of travel, he will return to city on exactly day to end the trip. Since Little W is a gourmet, every time he arrives at a city (including city on day and day ), he will taste the food of that city and gain the happiness it provides. If Little W arrives at the same city multiple times, he will gain happiness multiple times. Note that during the trip, Little W cannot stay in any city. That is, when he arrives at a city and the trip has not ended yet, he must depart immediately on the same day to another city.

For the figure above, one feasible travel plan of length days is :
- On day , Little W starts the trip from city , gains happiness , and departs for city .
- On day , Little W arrives at city , gains happiness , and departs for city .
- On day , Little W arrives at city , gains happiness , and departs for city .
- On day , Little W arrives at city , gains happiness , and departs for city .
- On day , Little W arrives at city , gains happiness , and departs for city .
- On day , Little W arrives at city , gains happiness , and ends the trip.
- The total happiness gained in this trip is .
In addition, the Elf Kingdom will hold food festivals at different times. Specifically, the -th food festival will be held in city on day . If Little W is in city on day , then when he tastes the food in city , he will gain an extra happiness. Now Little W asks you, as the reception envoy of the Elf Kingdom, to help him compute the maximum possible total happiness he can gain during the trip.
Input Format
Read data from standard input.
The first line contains four integers , representing the number of cities, the number of roads, the travel days, and the number of food festivals.
The second line contains integers , representing the happiness provided by the food in each city. Then follow lines, each containing three integers , representing the start city, end city, and travel days of each road.
Finally, there are lines, each containing three integers , representing the time, city, and extra happiness provided by each food festival.
The testdata guarantees:
- For all , . However, the testdata may contain multiple directed roads with the same route, i.e. there may exist such that and .
- For every city, there exists at least one directed road starting from that city.
- The times of all food festivals are pairwise distinct.
Output Format
Output to standard output.
Output a single integer in one line, representing the maximum total happiness Little W can obtain through traveling.
If Little W cannot return to city on day , output .
3 4 11 0
1 3 4
1 2 1
2 1 3
2 3 2
3 1 4
13
4 8 16 3
3 1 2 4
1 2 1
1 3 1
1 3 2
3 4 3
2 3 2
3 2 1
4 2 1
4 1 5
3 3 5
1 2 5
5 4 20
39
Hint
Explanation for Sample 1
This sample is the example in the statement. The optimal travel plan is shown in the statement.
Explanation for Sample 2
The optimal plan is .
- On day , Little W starts the trip from city , gains happiness , and travels along road .
- On day , Little W arrives at city , gains happiness , and travels along road .
- On day , Little W arrives at city , gains happiness due to the food festival, and travels along road .
- On day , Little W arrives at city , gains happiness , and travels along road .
- On day , Little W arrives at city , gains happiness , and travels along road .
- On day , Little W arrives at city , gains happiness , and travels along road .
- On day , Little W arrives at city , gains happiness , and ends the trip.
- The total happiness gained is .
Sample 3
See delicacy/delicacy3.in and delicacy/delicacy3.ans in the contestant directory.
This sample satisfies .
Constraints
For all test points:
, , , .
, , , .
The detailed limits for each test point are shown in the table below:
| Test Point ID | Special Constraints | |||
|---|---|---|---|---|
| None | ||||
| A | ||||
| None | ||||
Special constraint A: and .
Translated by ChatGPT 5