#P3872. [TJOI2010] 电影迷

    ID: 2809 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2010各省省选图的建立,建图最大流最小割天津

[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 XX a score vXv_X indicating how much he likes it. The score range is from 1000-1000 to 10001000, and a larger score means he likes it more. Each time Xiao A watches a movie XX, his experience increases by vXv_X.

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 X,YX, Y, there may be a dependency value dX,Yd_{X,Y}, meaning that if Xiao A watches XX but not YY, his experience will decrease by dX,Yd_{X,Y}. (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 00.

Input Format

  • The first line contains two integers: the total number of movies NN and the number of dependency relations MM.
  • The second line contains NN space-separated numbers, the scores for each movie.
  • Each of the next MM lines contains three integers X,Y,dX,YX, Y, d_{X,Y}, representing a dependency relation.
  • Each ordered pair (X,Y)(X, Y) appears at most once. 1X,YN1 \le X, Y \le N.

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 11, the experience is 10049=51100 - 49 = 51. If he only watches movie 22, the experience is 5010=60-50 - 10 = -60. If he watches both, the experience is 100+(50)=50100 + (-50) = 50. Therefore, he should only watch movie 11.

Constraints:

  • For 20%20\% of the testdata, 1N151 \le N \le 15.
  • For 100%100\% of the testdata, 1N1001 \le N \le 100, 1000vX1000-1000 \le v_X \le 1000, 0<dX,Y10000 < d_{X,Y} \le 1000.
  • Time limit per test point is 1 second.

Translated by ChatGPT 5