# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502522 | ismoilov | Schools (IZhO13_school) | C++14 | 191 ms | 13860 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).rbegin(), (x).rend()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
const int maxx = 3e5+5;
int a[maxx], b[maxx], pr[maxx], rp[maxx];
void S()
{
int n, ss, m;
cin >> n >> ss >> m;
vector <pair<pair<int, int>, int>> c;
fp(i,0,n){
cin >> a[i] >> b[i];
c.push_back({{a[i]-b[i], a[i]}, b[i]});
}
sort(all(c));
multiset <int> sc;
ll s = 0;
fpp(i,1,n){
s += c[i-1].first.second;
sc.insert(c[i-1].first.second);
if(sc.size() > ss)
s -= *sc.begin(), sc.erase(*sc.begin());
pr[i] = s;
}
s = 0;
sc.clear();
fm(i,n,0){
s += c[i-1].second;
sc.insert(c[i-1].second);
if(sc.size() > m)
s -= *sc.begin(), sc.erase(*sc.begin());
rp[i] = s;
}
ll ans = 0;
fpp(i,0,n){
ans = max(ans, (ll)(pr[i]+rp[i+1]));
}
cout << ans;
}
int main()
{
IOS;
S();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |