Untitled
unknown
c_cpp
a year ago
2.6 kB
2
Indexable
Never
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(x...) #endif #define int long long 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; }); long long ans = 0; set<pair<int, int>> ba; // all C vector<pair<int, int>> tmp; for (int j = 0; j < n; j++) { tmp.emplace_back(frs[j].c - frs[j].a, j); } sort(tmp.begin(), tmp.end()); auto it = tmp.begin(); int nxt = 0; vector<int> belong(n); for (int j = 0; j < n; j++, ++it) { if (j < x) { ans += frs[it->second].a; belong[it->second] = 1; } else if (j < x + y) { while (belong[nxt]) { nxt++; } ans += frs[nxt].b; ba.emplace(frs[nxt].b - frs[nxt].a, nxt); belong[nxt++] = 2; } else { while (belong[nxt]) { nxt++; } ans += frs[nxt].c; belong[nxt++] = 3; } } long long cur = ans; for (int i = 0; i < n; i++) { if (belong[i] == 2) continue; if (frs[i].b - frs[i].a > ba.begin()->first) { if (belong[i] == 1) { belong[i] = 2; ans += frs[i].b; ans -= frs[i].a; belong[ba.begin()->second] = 1; ans += frs[ba.begin()->second].a; ans -= frs[ba.begin()->second].b; ba.erase(ba.begin()); ba.emplace(frs[i].b - frs[i].a, i); } else if (belong[i] == 3) { belong[i] = 2; ans += frs[i].b; ans -= frs[i].c; belong[ba.begin()->second] = 3; ans += frs[ba.begin()->second].c; ans -= frs[ba.begin()->second].b; ba.erase(ba.begin()); ba.emplace(frs[i].b - frs[i].a, i); } } ans = max(ans, cur); } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); int tests = 1; // cin >> tests; while (tests--) { solve(); } return 0; }