# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49680 | mra2322001 | Schools (IZhO13_school) | C++14 | 2 ms | 608 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 f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 300002;
int n, s, t;
long t1[N], t2[N];
pii a[N];
istream& operator >> (istream &is, pii &iu){
cin >> iu.first >> iu.second;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> s >> t;
f1(i, n) cin >> a[i];
sort(a + 1, a + n + 1, [&](pii a1, pii a2){
return (a1.second - a1.first) < (a2.second - a2.first);
});
priority_queue <int, vector <int>, greater <int> > q;
f1(i, n){
if(q.size() < s){
t1[i] = t1[i - 1] + a[i].first;
q.push(a[i].first);
}
else if(q.top() < a[i].first){
t1[i] = t1[i - 1] - q.top() + a[i].first;
q.pop();
q.push(a[i].first);
}
else{
t1[i] = t1[i - 1];
}
}
while(q.size()) q.pop();
for(int i = n; i >= 1; i--){
if(q.size() < t){
t2[i] = t2[i + 1] + a[i].second;
q.push(a[i].second);
}
else if(q.top() < a[i].second){
t2[i] = t2[i + 1] - q.top() + a[i].second;
q.pop();
}
else{
t2[i] = t2[i + 1];
}
}
long res = 0;
f1(i, n){
res = max(res, t1[i] + t2[i + 1]);
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |