# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503378 | lukameladze | Schools (IZhO13_school) | C++14 | 2070 ms | 16184 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 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> s;
vector <pii> v;
main() {
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 (s.size() < m) {
s.insert(num);
sum += num;
}
else {
if (*(s.begin()) < num) {
sum -= *(s.begin());
s.erase(s.begin()); sum += num; s.insert(num);
}
} pr[i] = sum;
} sum = 0;
s.clear();
for (int i = (int)v.size() - 1; i >= 0; i--) {
num = b[v[i].s];
if (s.size() < k) {
s.insert(num); sum += num;
} else {
if (*(s.begin()) < num) {
sum -= *(s.begin());
s.erase(s.begin()); sum += num; s.insert(num);
}
}
sf[i] = sum;
}
for (int i = m; i <= n - k; i++) {
ans = max(ans, pr[i] + sf[i + 1]);
// cout<<i<<" "<<pr[i]<<" "<<sf[i + 1]<<endl;
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |