# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377365 | ijxjdjd | Schools (IZhO13_school) | C++14 | 230 ms | 18668 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>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int N;
int M, S;
cin >> N >> M >> S;
vector<pair<ll, ll>> vec(N);
FR(i, N) {
cin >> vec[i].first >> vec[i].second;
}
sort(all(vec), [](const auto& lhs, const auto& rhs) {
return lhs.first - lhs.second > rhs.first - rhs.second;
});
vector<ll> suf(N);
vector<ll> pref(N);
multiset<int> mx;
ll sm = 0;
for (int i = N-1; i >= 0; i--) {
mx.insert(vec[i].second);
sm += vec[i].second;
if (mx.size() > S) {
sm -= *mx.begin();
mx.erase(mx.begin());
}
suf[i] = sm;
}
mx.clear();
sm = 0;
for (int i = 0; i < N; i++) {
mx.insert(vec[i].first);
sm += vec[i].first;
if (mx.size() > M) {
sm -= *mx.begin();
mx.erase(mx.begin());
}
pref[i] = sm;
}
ll ans = max(suf[0], pref[N-1]);
for (int i = 0; i + 1 < N; i++) {
ans = max(pref[i] + suf[i+1], ans);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |