# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503379 | lukameladze | Schools (IZhO13_school) | C++14 | 2071 ms | 19752 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 f first
#define s second
#define pb push_back
#define int long long
#define pii pair <int, int>
using namespace std;
const int N = 3e5 + 5;
int n,m,k,a[N],b[N],sum,num,ans,pr[N],sf[N];
multiset <int> ms;
multiset <int> :: iterator it;
vector <pii> v;
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for (int i = 1; i <= n; i++) {
cin>>a[i]>>b[i];
v.pb({a[i] - b[i], i});
}
sort(v.begin(),v.end()); reverse(v.begin(),v.end());
for (int i = 0; i < v.size(); i++) {
num = a[v[i].s];
if (ms.size() < m) {
ms.insert(num);
sum += num;
}
else {
it = ms.begin();
if (*it < num) {
sum -= *it;
ms.erase(it);
sum += num; ms.insert(num);
}
} pr[i] = sum;
} sum = 0;
ms.clear();
for (int i = (int)v.size() - 1; i >= 0; i--) {
num = b[v[i].s];
if (ms.size() < k) {
ms.insert(num); sum += num;
} else {
it = ms.begin();
if (*it < num) {
sum -= *it;
ms.erase(it); sum += num; ms.insert(num);
}
}
sf[i] = sum;
}
for (int i = m; i <= n - k; i++) {
ans = max(ans, pr[i] + sf[i + 1]);
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |