Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
2.1 kB
2
Indexable
Never
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif

struct fr {
    int a, b, c;
};

void solve() {
    int x, y, z;
    cin >> x >> y >> z;
    int n = x + y + z;
    vector<fr> frs;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        frs.emplace_back(a, b, c);
    }
    sort(frs.begin(), frs.end(), [](fr lhs, fr rhs) {
        return lhs.c - lhs.b < rhs.c - rhs.b;
    });
    vector<long long> pref(n), suf(n);
    set<pair<int, int>> ca;
    long long suma = 0, sumc = 0, sumb = 0;
    for (int i = n - 1; i >= 0; i--) {
        auto it = ca.begin();
        if ((int)ca.size() < z) {
            ca.emplace(frs[i].c - frs[i].a, i);
            sumc += frs[i].c;
        } else if (it->first < frs[i].c - frs[i].a) {
            ca.emplace(frs[i].c - frs[i].a, i);
            sumc += frs[i].c;
            sumc -= frs[it->second].c;
            suma += frs[it->second].a;
            ca.erase(it);
        } else {
            suma += frs[i].a;
        }
        if ((int)ca.size() == z) {
            suf[i] = suma + sumc;
        }
    }
    long long ans = 0;
    set<pair<int, int>> ba;
    suma = 0;
    for (int i = 0; i < x + y; i++) {
        auto it = ba.begin();
        if ((int)ba.size() < y) {
            ba.emplace(frs[i].b - frs[i].a, i);
            sumb += frs[i].b;
        } else if (it->first < frs[i].b - frs[i].a) {
            ba.emplace(frs[i].b - frs[i].a, i);
            sumb += frs[i].b;
            sumb -= frs[it->second].b;
            suma += frs[it->second].a;
            ba.erase(it);
        } else {
            suma += frs[i].a;
        }
        if ((int)ba.size() == y) {
            pref[i] = suma + sumb;
            ans = max(ans, pref[i] + suf[i + 1]);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }
    return 0;
}