Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define ar array
- typedef long long ll;
- const int N = 1e5 + 5;
- int x[N], y[N], z[N];
- ll res_pref[N], res_suff[N];
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int X, Y, Z;
- cin >> X >> Y >> Z;
- int n = X + Y + Z;
- for (int i = 0; i < n; i++) {
- cin >> x[i] >> y[i] >> z[i];
- }
- vector<int> p(n);
- iota(p.begin(), p.end(), 0);
- sort(p.begin(), p.end(),
- [&](int i, int j) { return y[i] - x[i] < y[j] - x[j]; });
- ll ans = 0;
- priority_queue<int> pref, suff;
- for (int i = 0; i < n; i++) {
- if (i)
- res_pref[i] = res_pref[i - 1];
- res_pref[i] += x[p[i]];
- pref.push(z[p[i]] - x[p[i]]);
- if (i >= X) {
- res_pref[i] += pref.top();
- pref.pop();
- }
- }
- for (int i = n - 1; ~i; i--) {
- if (i + 1 < n)
- res_suff[i] = res_suff[i + 1];
- res_suff[i] += y[p[i]];
- suff.push(z[p[i]] - y[p[i]]);
- if (i + Y < n) {
- res_suff[i] += suff.top();
- suff.pop();
- }
- }
- for (int i = X - 1; i + Y < n; i++) {
- ans = max(ans, res_pref[i] + res_suff[i + 1]);
- }
- cout << ans << "\n";
- }
- /*
- 1 2 1
- 2 4 4
- 3 2 1
- 7 6 7
- 5 2 3
- */
Advertisement
Comments
-
- (~i) means (i != -1), how I understood. these solutions are so difficult, I can't really understand them, maybe I just haven't solved that many to understand
Add Comment
Please, Sign In to add comment
Advertisement