# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90537 | popovicirobert | Schools (IZhO13_school) | C++14 | 112 ms | 8180 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 lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = (int) 3e5;
pair <int, int> arr[MAXN + 1];
bool cmp(pair <int, int> a, pair <int, int> b) {
/*if(a.first - a.second == b.first - b.second) {
return a.second < b.second;
}*/
return a.first - a.second > b.first - b.second;
}
ll pref[MAXN + 1], suff[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, s;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> s;
for(i = 1; i <= n; i++) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr + 1, arr + n + 1, cmp);
priority_queue <int> mst;
ll cur = 0;
for(i = 1; i <= n; i++) {
if(mst.size() < m) {
mst.push(-arr[i].first);
cur += arr[i].first;
}
else if(-(mst.top()) < arr[i].first) {
cur += mst.top();
mst.pop();
mst.push(-arr[i].first);
cur += arr[i].first;
}
pref[i] = cur;
}
while(!mst.empty()) {
mst.pop();
}
cur = 0;
for(i = n; i >= 1; i--) {
if(mst.size() < s) {
mst.push(-arr[i].second);
cur += arr[i].second;
}
else if(-(mst.top()) < arr[i].second) {
cur += mst.top();
mst.pop();
mst.push(-arr[i].second);
cur += arr[i].second;
}
suff[i] = cur;
}
ll ans = 0;
for(i = m; i <= n - s; i++) {
ans = max(ans, pref[i] + suff[i + 1]);
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |