National Olympiad in Informatics, China, 2006
New technology is bombarding the mobile communications market. For major cellphone carriers, this is both an opportunity and a challenge. The THU Group's CS&T communications company is at the eve of a bloody battle in a new generation of communication technology. So much preparatory work needs to be done. For the site-selection aspect alone, they will need to complete prior market research, site investigation, optimization, and other projects.
After the market research and site investigation, the company has
determined a total of
The company also researched the expected user base, consisting of
The THU Group's CS&T company can select a group of relay stations to establish (thus paying the necessary principal cost), servicing certain customer groups (thus receiving revenue). How must they select which relay stations to establish so that the company can receive the maximum possible profit? (Profit = total revenue - total principal cost)
Input Specification
The first line of input contains two integers
The second line contains
There will be
Output Specification
Your program should output a single integer, representing the maximum profit that the company can obtain.
Sample Input
5 5
1 2 3 4 5
1 2 3
2 3 4
1 3 3
1 4 2
4 5 3
Sample Output
4
Explanation
By building relay stations 1, 2, and 3, the total principal cost will be 6, and the total revenue will be 10. This yields the maximum profit of 4.
Constraints
For 80% of the test cases:
For 100% of the test cases:
Problem translated to English by .
Comments