# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
611840 | ekwoo | Schools (IZhO13_school) | C++17 | 103 ms | 3700 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+7;
vector<pair<int,int>> e;
int main(){
int n, m, s;
scanf("%d%d%d",&n,&m,&s); e.resize(n);
for(auto&[x,y]:e) scanf("%d%d",&x,&y);
sort(e.begin(), e.end(), [](const pair<int,int> x, const pair<int,int> y){return x.first-x.second < y.first-y.second;});
priority_queue<int> pq;
long long p=0, q=0;
for(int i=0; i<n; ++i){
pq.push(-e[i].second);
q+=e[i].second;
while(pq.size()>s) q+=pq.top(), pq.pop();
e[i].second = q;
}
pq = priority_queue<int> (); q=0;
for(int i=n; i--;){
pq.push(-e[i].first);
q+=e[i].first;
while(pq.size()>m) q+=pq.top(), pq.pop();
p = max(p, i?q+e[i-1].second:q);
}
printf("%lld",p);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |