#P3872. [TJOI2010] 电影迷
[TJOI2010] 电影迷
Description
Xiao A is a movie buff. He has collected hundreds of movies and plans to pick some to watch during the holidays. Based on his taste and online information, he assigned to each movie a score indicating how much he likes it. The score range is from to , and a larger score means he likes it more. Each time Xiao A watches a movie , his experience increases by .
In addition, because some movies belong to the same series (for example, the famous Terminator series, The Matrix series, etc.), if Xiao A watches an earlier one but not a later one, he will feel uncomfortable. More precisely, for any two distinct movies , there may be a dependency value , meaning that if Xiao A watches but not , his experience will decrease by . (Note that the viewing order does not matter; as long as both are watched, there is no penalty.)
Now he wants to select some movies to watch to maximize the total experience. If he cannot obtain a positive experience, output .
Input Format
- The first line contains two integers: the total number of movies and the number of dependency relations .
- The second line contains space-separated numbers, the scores for each movie.
- Each of the next lines contains three integers , representing a dependency relation.
- Each ordered pair appears at most once. .
Output Format
Output one integer, the maximum experience Xiao A can obtain.
2 2
100 -50
1 2 49
2 1 10
51
Hint
If Xiao A only watches movie , the experience is . If he only watches movie , the experience is . If he watches both, the experience is . Therefore, he should only watch movie .
Constraints:
- For of the testdata, .
- For of the testdata, , , .
- Time limit per test point is 1 second.
Translated by ChatGPT 5
京公网安备 11011102002149号