#P7507. [2017年杭电多校]Give out candies
[2017年杭电多校]Give out candies
Give out candies
Problem Description
There are children numbered to , and HazelFan's task is to give out candies to the children. Each children must be given at least and at most candies. The children raised pieces of requirements, and every piece includes three integers , means that the number of candies given to the child numbered , subtract the number of candies given to the child number , the result should not be more than . Besides, if the child numbered is given candies, he or she will get satisfaction score, now you need to help HazelFan maximize the sum of the satisfaction scores of these children.
Input
The first line contains a positive integer , denoting the number of test cases. For each test case: The first line contain three positive integers . The next lines, the th line contains positive integers, the th integer denotes . The next lines, each line contains three integers , denoting a piece of requirement.
Output
For each test case: A single line contains a nonnegative integer, denoting the answer. Particularly, if there is no way to give out candies, print -1.
Sample Input
2
2 1 1
1
1
1 2 1
3 3 2
1 2 3
2 3 1
3 1 2
1 2 0
2 3 0
Sample Output
2
7
Source
2017 Multi-University Training Contest - Team 7