Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

//int a[305][305];

struct node{
    LL a,b,c;
    node(){}
    node(LL a,LL b,LL c):a(a),b(b),c(c){}
};

vector<node> s,s1,s2,s3;

bool cmp(const node &a,const node &b){
    return a.c-a.a<b.c-b.a;
}

bool cmp1(const node &a,const node &b){
    return a.b-a.a<b.b-b.a;
}

bool cmp2(const node &a,const node &b){
    return a.b-a.c<b.b-b.c;
}

bool cmp3(const node &a,const node &b){
    return a.c-a.a<b.c-b.a;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    /*int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }*/
    int x,y,z;cin>>x>>y>>z;
    LL sum=0;
    int a,b,c;
    for(int i=1;i<=x+y+z;i++){
        cin>>a>>b>>c;
        s.push_back(node(a,b,c));
    }
    sort(s.begin(),s.end(),cmp);
    for(int i=1;i<=x;i++){
        s1.push_back(s[i-1]);
        sum+=s[i-1].a;
    }
    for(int i=1;i<=y;i++){
        s2.push_back(s[i+x-1]);
        sum+=s[i+x-1].b;
    }
    for(int i=1;i<=z;i++){
        s3.push_back(s[i+x+y-1]);
        sum+=s[i+x+y-1].c;
    }
    sort(s1.begin(),s1.end(),cmp1);
    sort(s2.begin(),s2.end(),cmp1);
    int p,q;
    p=x-1,q=0;
    while(s1[p].b+s2[q].a>s1[p].a+s2[q].b&&p>=0&&q<y){
        sum+=(s1[p].b+s2[q].a)-(s1[p].a+s2[q].b);
        swap(s1[p],s2[q]);
        p--;q++;
    }
    sort(s2.begin(),s2.end(),cmp2);
    sort(s3.begin(),s3.end(),cmp2);
    p=z-1,q=0;
    while(s3[p].b+s2[q].c>s3[p].c+s2[q].b&&p>=0&&q<y){
        sum+=(s3[p].b+s2[q].c)-(s3[p].c+s2[q].b);
        swap(s3[p],s2[q]);
        p--;q++;
    }
    sort(s1.begin(),s1.end(),cmp3);
    sort(s3.begin(),s3.end(),cmp3);
    p=x-1,q=0;
    while(s1[p].c+s3[q].a>s1[p].a+s3[q].c&&p>=0&&q<z){
        sum+=(s1[p].c+s3[q].a)-(s1[p].a+s3[q].c);
        swap(s1[p],s3[q]);
        p--;q++;
    }
    sort(s1.begin(),s1.end(),cmp1);
    sort(s2.begin(),s2.end(),cmp1);
    int p,q;
    p=x-1,q=0;
    while(s1[p].b+s2[q].a>s1[p].a+s2[q].b&&p>=0&&q<y){
        sum+=(s1[p].b+s2[q].a)-(s1[p].a+s2[q].b);
        swap(s1[p],s2[q]);
        p--;q++;
    }
    sort(s2.begin(),s2.end(),cmp2);
    sort(s3.begin(),s3.end(),cmp2);
    p=z-1,q=0;
    while(s3[p].b+s2[q].c>s3[p].c+s2[q].b&&p>=0&&q<y){
        sum+=(s3[p].b+s2[q].c)-(s3[p].c+s2[q].b);
        swap(s3[p],s2[q]);
        p--;q++;
    }
    sort(s1.begin(),s1.end(),cmp3);
    sort(s3.begin(),s3.end(),cmp3);
    p=x-1,q=0;
    while(s1[p].c+s3[q].a>s1[p].a+s3[q].c&&p>=0&&q<z){
        sum+=(s1[p].c+s3[q].a)-(s1[p].a+s3[q].c);
        swap(s1[p],s3[q]);
        p--;q++;
    }
    cout<<sum<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:109:9: error: redeclaration of 'int p'
  109 |     int p,q;
      |         ^
a.cc:84:9: note: 'int p' previously declared here
   84 |     int p,q;
      |         ^
a.cc:109:11: error: redeclaration of 'int q'
  109 |     int p,q;
      |           ^
a.cc:84:11: note: 'int q' previously declared here
   84 |     int p,q;
      |           ^