#P4174. [NOI2006] 最大获利

    ID: 3113 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2006NOI 系列网络流广度优先搜索,BFS深度优先搜索,DFS最大流

[NOI2006] 最大获利

Description

New technologies are impacting the mobile communications market. For major operators, this is both an opportunity and a challenge. On the eve of the battle over next-generation communication technologies, the CS&T Communications company under the THU Group has a lot to prepare. Even for site selection alone, they need to complete preliminary market research, site surveys, and optimization.

After the preliminary market research and site surveys, the company has identified a total of NN candidate locations for communication relay stations. Due to geographical differences, the cost of building a relay station varies by location. Fortunately, after the preliminary investigation, these data are known: the cost to build the ii-th relay station is PiP_i (1iN1 \leq i \leq N).

In addition, the company has identified all target user groups, a total of MM. The information for the ii-th user group is summarized by AiA_i, BiB_i, and CiC_i: these users will use relay station AiA_i and relay station BiB_i to communicate, and the company can gain a profit of CiC_i (1iM1 \leq i \leq M, 1Ai,BiN1 \leq A_i, B_i \leq N).

The CS&T company under THU can choose to build some relay stations (incurring costs), serve some user groups, and obtain revenue (the sum of gains). How should the company choose which relay stations to build to maximize net profit? (Net profit = sum of gains − sum of costs.)

Input Format

The first line of the input contains two positive integers NN and MM.

The second line contains NN integers describing the construction cost of each relay station, in order: P1,P2,,PNP_1 , P_2 , …,P_N.

The following MM lines: the (i+2)(i + 2)-th line contains three numbers AiA_i, BiB_i, and CiC_i describing the information of the ii-th user group.

All variables have the meanings described in the problem statement.

Output Format

Output a single integer, representing the maximum net profit the company can obtain.

5 5
1 2 3 4 5
1 2 3
2 3 4
1 3 3
1 4 2
4 5 3
4

Hint

Example: choose to build relay stations 1,2,31, 2, 3. The total cost is 66, and the total gain is 1010, so the maximum profit is 44.

For 100%100\% of the testdata: N5000N \leq 5\,000, M50000M \leq 50\,000, 0Ci1000 \leq C_i \leq 100, 0Pi1000 \leq P_i \leq 100.

Translated by ChatGPT 5