# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167111 | abil | Schools (IZhO13_school) | C++14 | 281 ms | 13976 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 fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (3e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
pair<int,pair<int,int > > a[N];
multiset<int > st;
long long pr[N], sf[N];
main()
{
int n, m, s;
long long sum = 0;
scanf("%d%d%d", &n, &m, &s);
for(int i = 1;i <= n; i++){
scanf("%d%d", &a[i].sc.fr, &a[i].sc.sc);
a[i].fr = a[i].sc.sc - a[i].sc.fr;
}
sort(a + 1,a + 1 + n);
for(int i = 1;i <= n; i++){
sum += a[i].sc.fr;
st.insert(a[i].sc.fr);
if(i > m){
sum -= *st.begin();
st.erase(st.begin());
}
pr[i] = sum;
}
st.clear();
sum = 0;
for(int i = n;i >= 1; i--){
sum += a[i].sc.sc;
st.insert(a[i].sc.sc);
if(i <= n - s){
sum -= *st.begin();
st.erase(st.begin());
}
sf[i] = sum;
}
long long ans = 0;
for(int i = max(1, m);i <= n - s; i++){
ans = max(ans, pr[i] + sf[i + 1]);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |