# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117399 | stefanneagu | Schools (IZhO13_school) | C++17 | 225 ms | 15176 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>
using namespace std;
const int nmax = 3e5 + 1;
struct str {
int dif, a, b;
} v[nmax];
bool cmp(str x, str y) {
return x.dif > y.dif;
}
int dp1[nmax], dp2[nmax];
int32_t main() {
int n, m, s;
cin >> n >> m >> s;
for(int i = 1; i <= n; i++) {
cin >> v[i].a >> v[i].b;
v[i].dif = v[i].a - v[i].b;
}
sort(v + 1, v + n + 1, cmp);
multiset<int> ms;
int sum = 0;
for(int i = 1; i <= n; i++) {
ms.insert(v[i].a);
sum += v[i].a;
if(ms.size() > m) {
sum -= *ms.begin();
ms.erase(ms.lower_bound(*ms.begin()));
}
dp1[i] = sum;
// cout << i << ": " << dp1[i] << '\n';
}
// cout << '\n';
ms.clear();
sum = 0;
for(int i = n; i >= 1; i--) {
ms.insert(v[i].b);
sum += v[i].b;
if(ms.size() > s) {
sum -= *ms.begin();
ms.erase(ms.lower_bound(*ms.begin()));
}
dp2[i] = sum;
// cout << i << ": " << dp2[i] << '\n';
}
int ans = 0;
for(int i = m; i <= n - s; i++) {
ans = max(ans, dp1[i] + dp2[i + 1]);
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |