# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
164415 | tselmegkh | Schools (IZhO13_school) | C++14 | 540 ms | 14276 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 N = 3e5 + 5;
long long sum[N][2];
int main(){
int n, m, s;
cin >> n >> m >> s;
vector<pair<int, pair<int, int>>> v1;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
v1.push_back({a - b, {a, b}});
}
sort(v1.rbegin(), v1.rend());
long long tot = 0;
multiset<long long> ms;
for(int i = 0; i < n; i++){
ms.insert(v1[i].second.first);
tot += v1[i].second.first;
if(ms.size() > m){
tot -= *ms.begin();
ms.erase(ms.begin());
}
sum[i + 1][0] = tot;
}
tot = 0;
ms.clear();
for(int i = n - 1; i >= 0; i--){
ms.insert(v1[i].second.second);
tot += v1[i].second.second;
if(ms.size() > s){
tot -= *ms.begin();
ms.erase(ms.begin());
}
sum[i + 1][1] = tot;
}
long long ans = 0;
for(int i = m; i <= n - s; i++){
ans = max(ans, sum[i][0] + sum[i + 1][1]);
}
cout << ans << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |