# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
363267 | Ruxandra985 | Schools (IZhO13_school) | C++14 | 306 ms | 18668 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 DIMN 300010
using namespace std;
int x[DIMN] , y[DIMN];
long long prefix[DIMN] , sufix[DIMN];
pair <int , int> v[DIMN];
multiset <int> w ;
int cmp (pair <int , int> a , pair <int , int> b){
return a > b;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , s , i;
long long suma , sol = 0;
multiset<int> :: iterator it , it2;
fscanf (fin,"%d%d%d",&n,&m,&s);
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%d%d",&x[i],&y[i]);
v[i] = make_pair(x[i] - y[i] , i);
}
sort (v + 1 , v + n + 1 , cmp);
/// v = ordinea prioritatilor
suma = 0;
for (i = 1 ; i <= m ; i++){
suma += x[v[i].second];
w.insert(x[v[i].second]);
prefix[i] = suma;
}
for (i = m + 1 ; i <= n ; i++){
prefix[i - 1] = suma;
w.insert(x[v[i].second]);
suma += x[v[i].second];
suma = suma - *w.begin();
w.erase(w.begin());
}
prefix[n] = suma;
/// ------------------------------------------------------------------
w.clear();
suma = 0;
for (i = n ; n - i + 1 <= s ; i--){
suma += y[v[i].second];
w.insert(y[v[i].second]);
sufix[i] = suma;
}
for (i = n - s ; i ; i--){
sufix[i + 1] = suma;
w.insert(y[v[i].second]);
suma += y[v[i].second];
suma = suma - *w.begin();
w.erase(w.begin());
}
sufix[1] = suma;
for (i = 0 ; i <= n ; i++){
sol = max(sol , prefix[i] + sufix[i + 1]);
}
fprintf (fout,"%lld",sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |