#P1791. [国家集训队] 人员雇佣

[国家集训队] 人员雇佣

Description

As a business-savvy tycoon, Xiao LL decides to hire some of the best managers in his country to run his company. There is a collaboration contribution index among these managers (we use Ei,jE_{i,j} to denote how well manager ii knows manager jj). That is, when manager ii and manager jj are both hired, manager ii contributes to manager jj, increasing the profit by Ei,jE_{i,j}.

Of course, hiring each manager costs some money AiA_i. For some managers, their contribution may not be worth the cost, so, being smart, Xiao LL will not hire them. However, those who are not hired will be hired by competitors. In that case, they will affect the work of the managers you hire, decreasing the profit by Ei,jE_{i,j} (note: this Ei,jE_{i,j} is the same as above).

Being efficiency-first, Xiao LL wants to hire some people to maximize the net profit. Can you help Xiao LL solve this problem?

Input Format

  • The first line contains an integer NN, the number of managers.
  • The second line contains NN integers AiA_i, the cost to hire each manager.
  • The next NN lines each contain NN numbers, giving Ei,jE_{i,j}, i.e., how well manager ii knows manager jj. It holds that Ei,j=Ej,iE_{i,j} = E_{j,i}.

Output Format

The first line contains one integer, the maximum value.

3
3 5 100
0 6 1
6 0 2
1 2 0
1

Hint

  • For 20% of the testdata, N10N \le 10.
  • For 50% of the testdata, N100N \le 100.
  • For 100% of the testdata, N1000N \le 1000, Ei,j<231E_{i,j} < 2^{31}, Ai<231A_i < 2^{31}.

From Lin Yankai.

Translated by ChatGPT 5