Problem Statement
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has Ai gold coins, Bi silver coins and Ci bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
- 1≤X
- 1≤Y
- 1≤Z
- X+Y+Z≤105
- 1≤Ai≤109
- 1≤Bi≤109
- 1≤Ci≤109
Input
Input is given from Standard Input in the following format:
X Y ZA1 B1 C1A2 B2 C2:AX+Y+Z BX+Y+Z CX+Y+Z
Output
Print the maximum possible total number of coins of all colors he gets.
Sample Input 1
1 2 12 4 43 2 17 6 75 2 3
Sample Output 1
18
Get silver coins from Person 1, silver coins from Person 2, bronze coins from Person 3 and gold coins from Person 4. In this case, the total number of coins will be 4+2+7+5=18. It is not possible to get 19 or more coins, and the answer is therefore 18.
Sample Input 2
3 3 216 17 12 7 52 16 1217 7 713 2 1012 18 316 15 195 6 2
Sample Output 2
110
Sample Input 3
6 2 433189 87907 27734974271616 46764 5753065208801 53151 32716125158589 4337 79669768666854 17565 28991058350598 35195 47811268913919 88414 1039624557953 69657 69925375244255 98144 4684437092332 42580 75243709739752 19060 84506286960126 74101 382963164
Sample Output 3
3093929975
用(ai-ci,bi-ci,0)替换(ai,bi,ci)的想法非常精彩。排序时的考虑也值得思考。
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include