Problem:
Score : 800 points

Problem Statement

There are X+Y+Z people, conveniently numbered 1 through X+Y+Z.
Person i has A_i gold coins, B_i silver coins and C_i 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 \leq X

1 \leq Y

1 \leq Z

X+Y+Z \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

1 \leq C_i \leq 10^9

Input

Input is given from Standard Input in the following format:

X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}

Output

Print the maximum possible total number of coins of all colors he gets.

Sample Input 1

1 2 1
2 4 4
3 2 1
7 6 7
5 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 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2

Sample Output 2

110

Sample Input 3

6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164

Sample Output 3

3093929975

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <cstdlib>

int X, Y, Z;
long long A[100010], B[100010], C[100010];
int num[100010];
int n;
int idx[100010];
long long res;

long long H[6][200100];
int H2[6][200100];
int Hns[6];
int Hn;
void addHeap(int d, long long x, int p)
{
	Hn = Hns[d];
	Hn ++;
	H[d][Hn] = x;
	H2[d][Hn] = p;
	int i=Hn, j;
	while(i>1){
		j = i/2;
		if(H[d][j] < x){
			H[d][i] = H[d][j];
			H2[d][i] = H2[d][j];
			i = j;
		}
		else
			break;
	}
	H[d][i] = x;
	H2[d][i] = p;
	Hns[d] = Hn;
}

void delHeap(int d, long long &x, int &p)
{
	Hn = Hns[d];
	x = H[d][1];
	p = H2[d][1];
	long long tmp = H[d][Hn];
	int tmp2 = H2[d][Hn];
	Hn --;
	int i = 1, j;
	while(2*i<=Hn){
		j = 2*i;
		if(j+1<=Hn && H[d][j+1]>H[d][j])
			j ++;
		if(H[d][j] > tmp){
			H[d][i] = H[d][j];
			H2[d][i] = H2[d][j];
			i = j;
		}
		else
			break;
	}
	H[d][i] = tmp;
	H2[d][i] = tmp2;
	Hns[d] = Hn;
}

void getHeap(int d, long long &x, int &p)
{
	x = H[d][1];
	p = H2[d][1];
}

int cmp1(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	return A[i2] - A[i1];
}

int cmp2(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	return B[i2] - B[i1];
}

int cmp3(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	return C[i2] - C[i1];
}

void solve()
{
	int i;
	res = 0;
	n = X + Y + Z;
	for(i=0; i<n; i++)
		num[i] = -1;
	for(i=0; i<n; i++)
		idx[i] = i;
	qsort(idx, n, sizeof(int), cmp1);
	int cnt = 0;
	for(i=0; i<n; i++){
		if(num[idx[i]] == -1){
			num[idx[i]] = 0;
			res += A[idx[i]];
			cnt ++;
			if(cnt == X)
				break;
		}
	}
	
	for(i=0; i<n; i++)
		idx[i] = i;
	qsort(idx, n, sizeof(int), cmp2);
	cnt = 0;
	for(i=0; i<n; i++){
		if(num[idx[i]] == -1){
			num[idx[i]] = 1;
			res += B[idx[i]];
			cnt ++;
			if(cnt == Y)
				break;
		}
	}
	
	for(i=0; i<n; i++)
		idx[i] = i;
	qsort(idx, n, sizeof(int), cmp3);
	cnt = 0;
	for(i=0; i<n; i++){
		if(num[idx[i]] == -1){
			num[idx[i]] = 2;
			res += C[idx[i]];
			cnt ++;
			if(cnt == Z)
				break;
		}
	}
	
	Hns[0] = Hns[1] = Hns[2] = Hns[3] = Hns[4] = Hns[5] = 0;
	for(i=0; i<n; i++){
		if(num[i] == 0){
			addHeap(0, B[i]-A[i], i);
			addHeap(1, C[i]-A[i], i);
		}
		else if(num[i] == 1){
			addHeap(2, A[i]-B[i], i);
			addHeap(3, C[i]-B[i], i);
		}
		else{
			addHeap(4, A[i]-C[i], i);
			addHeap(5, B[i]-C[i], i);
		}
	}
	while(1){
		long long x1, x2;
		int p1, p2;
		while(1){
			delHeap(0, x1, p1);
			if(num[p1] == 0)
				break;
		}
		while(1){
			delHeap(2, x2, p2);
			if(num[p2] == 1)
				break;
		}
		if(x1+x2>0){
			num[p1] = 1;
			num[p2] = 0;
			addHeap(2, A[p1]-B[p1], p1);
			addHeap(3, C[p1]-B[p1], p1);
			addHeap(0, B[p2]-A[p2], p2);
			addHeap(1, C[p2]-A[p2], p2);
			res += x1+x2;
			continue;
		}
		addHeap(0, x1, p1);
		addHeap(2, x2, p2);
		
		while(1){
			delHeap(1, x1, p1);
			if(num[p1] == 0)
				break;
		}
		while(1){
			delHeap(4, x2, p2);
			if(num[p2] == 2)
				break;
		}
		if(x1+x2>0){
			num[p1] = 2;
			num[p2] = 0;
			addHeap(4, A[p1]-C[p1], p1);
			addHeap(5, B[p1]-C[p1], p1);
			addHeap(0, B[p2]-A[p2], p2);
			addHeap(1, C[p2]-A[p2], p2);
			res += x1+x2;
			continue;
		}
		addHeap(1, x1, p1);
		addHeap(4, x2, p2);
		
		while(1){
			delHeap(3, x1, p1);
			if(num[p1] == 1)
				break;
		}
		while(1){
			delHeap(5, x2, p2);
			if(num[p2] == 2)
				break;
		}
		if(x1+x2>0){
			num[p1] = 2;
			num[p2] = 1;
			addHeap(4, A[p1]-C[p1], p1);
			addHeap(5, B[p1]-C[p1], p1);
			addHeap(2, A[p2]-B[p2], p2);
			addHeap(3, C[p2]-B[p2], p2);
			res += x1+x2;
			continue;
		}
		addHeap(3, x1, p1);
		addHeap(5, x2, p2);
		
		break;
	}
	printf("%lld\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d%d%d", &X, &Y, &Z);
	for(i=0; i<X+Y+Z; i++)
		scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
	solve();
	return 0;
}