# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249731 | srvlt | Schools (IZhO13_school) | C++14 | 205 ms | 15224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 3e5 + 123;
int n, m, s;
ll suf[n0];
struct Pair {
int x, y;
bool operator < (const Pair & p) const {
return x - y > p.x - p.y;
}
};
Pair p[n0];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> n >> m >> s;
for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
sort(p, p + n);
multiset <int> A, B;
for (int i = n - 1; i >= 0; i--) {
suf[i] = suf[i + 1] + p[i].y;
B.insert(p[i].y);
if (SZ(B) > s) {
suf[i] -= *B.begin();
B.erase(B.begin());
}
}
ll cur = 0, res = 0;
for (int i = 0; i < n - s; i++) {
cur += p[i].x;
A.insert(p[i].x);
if (SZ(A) > m) {
cur -= *A.begin();
A.erase(A.begin());
}
if (i >= m - 1) res = max(res, cur + suf[i + 1]);
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |