# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
446077 | ak2006 | Schools (IZhO13_school) | C++14 | 259 ms | 22424 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;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
bool cmp(vl&f,vl&s)
{
return f[0] - s[0] > f[1] - s[1];
}
int main()
{
setIO();
int n,m,s;
cin>>n>>m>>s;
vvl a(n + 1,vl(2));
for (int i = 1;i<=n;i++)cin>>a[i][0]>>a[i][1];
sort(a.begin() + 1,a.end(),cmp);
vl pref(n + 1),suf(n + 1);
priority_queue<ll>q;
ll sum = 0;
for (int i = 1;i<=n;i++){
q.push(-a[i][0]);
sum += a[i][0];
if (q.size() > m){
ll val = -q.top();
q.pop();
sum -= val;
}
pref[i] = sum;
}
while (!q.empty())q.pop();
sum = 0;
for (int i = n;i>=1;i--){
q.push(-a[i][1]);
sum += a[i][1];
if (q.size() > s){
ll val = -q.top();
q.pop();
sum -= val;
}
suf[i] = sum;
}
ll ans = 0;
for (int i = m;i<=n;i++)
if (n - i >= s)ans = max(ans,pref[i] + suf[i + 1]);
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |