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 (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct binaryHeap{
  void *h;
  size_t heapSize;
  size_t maxSize;
  size_t size;
  int (*cmp)(const void *,const void *);
} heap;

heap* newHeap(const size_t size,int (*cmpF)(const void *,const void *)){
  const size_t maxSize=1;
  heap *res=(heap *)malloc(sizeof(heap));
  res->h=malloc(size*(maxSize+1));
  res->heapSize=0;
  res->maxSize=maxSize;
  res->size=size;
  res->cmp=cmpF;
  return res;
}

int isEmpty(const heap *h){
  return h->heapSize==0;
}

void freeHeap(heap *h){
  free(h->h);
  free(h);
  return;
}

void initHeap(heap *h){
  h->heapSize=0;
  return;
}

static inline void heapFunc_swap(void * restrict a,void * restrict b,void * restrict tmp,size_t size){
  memcpy(tmp,a,size);
  memcpy(a,b,size);
  memcpy(b,tmp,size);
  return;
}

void push(heap *q,const void *p){
  if(q->heapSize==q->maxSize){
    q->maxSize*=2;
    q->h=realloc(q->h,q->size*(q->maxSize+1));
  }
  q->heapSize+=1;
  char *h=(char *)(q->h);
  int k=q->heapSize;
  const size_t size=q->size;
  int (*cmp)(const void *,const void *)=q->cmp;
  memcpy(h+k*size,p,size);
  while(k>1){
    size_t parent=k/2;
    if(cmp(h+parent*size,h+k*size)<=0) return;
    heapFunc_swap(h+parent*size,h+k*size,h,size);
    k=parent;
  }
  return;
}

void pop(heap *q,void *res){
  char *h=(char *)(q->h);
  const size_t size=q->size;
  if(res!=NULL) memcpy(res,h+size,size);
  memcpy(h+size,h+size*q->heapSize,size);
  q->heapSize-=1;
  int (*cmp)(const void *,const void *)=q->cmp;
  const size_t n=q->heapSize;
  size_t k=1;
  while(2*k+1<=n){
    size_t next=cmp(h+2*k*size,h+(2*k+1)*size)<=0?2*k:2*k+1;
    if(cmp(h+k*size,h+next*size)<=0) return;
    heapFunc_swap(h+k*size,h+next*size,h,size);
    k=next;
  }
  if(2*k<=n && cmp(h+k*size,h+2*k*size)>0) heapFunc_swap(h+k*size,h+2*k*size,h,size);
  return;
}

void top(const heap *q,void *res){
  memcpy(res,(char *)q->h+q->size,q->size);
  return;
}

typedef long long int int64;

typedef struct coins{
  int a,b,c;
} node;

int cmpAB(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  return (p->b-p->a)-(q->b-q->a);
}

int cmpAC(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  return -((p->c-p->a)-(q->c-q->a));
}

int cmpBC(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  return -((p->c-p->b)-(q->c-q->b));
}

void run(void){
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);
  const int n=x+y+z;
  node *p=(node *)calloc(n,sizeof(node));
  int i;
  for(i=0;i<n;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    p[i]=(node){a,b,c};
  }
  qsort(p,n,sizeof(node),cmpAB);
  int64 *front=(int64 *)calloc(z+1,sizeof(int64));
  int64 *back=(int64 *)calloc(z+1,sizeof(int64));
  heap *h=newHeap(sizeof(node),cmpAC);
  int64 sum=0;
  for(i=0;i<x;i++){
    sum+=p[i].a;
    push(h,p+i);
  }
  front[0]=sum;
  for(i=x;i<n-y;i++){
    sum+=p[i].a;
    push(h,p+i);
    node t;
    pop(h,&t);
    sum+=t.c-t.a;
    front[i-x+1]=sum;
  }
  freeHeap(h);
  h=newHeap(sizeof(node),cmpBC);
  sum=0;
  for(i=n-1;i>=n-y;i--){
    sum+=p[i].b;
    push(h,p+i);
  }
  back[z]=sum;
  for(i=n-y-1;i>=x;i--){
    sum+=p[i].b;
    push(h,p+i);
    node t;
    pop(h,&t);
    sum+=t.c-t.b;
    back[i-x]=sum;
  }
  int64 max=0;
  for(i=0;i<=z;i++) {
    int64 t=front[i]+back[i];
    if(max<t) max=t;
  }
  printf("%lld\n",max);
}

int main(void){
  run();
  return 0;
}