# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169569 | davitmarg | Schools (IZhO13_school) | C++17 | 233 ms | 16356 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.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 300005;
int n, m, s, k;
LL ans = 0;
pair<LL, LL> a[N];
multiset<LL> M, S;
vector<pair<LL, LL>> K;
int main()
{
cin >> n >> m >> s;
k = n - m - s;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
return a.first - a.second < b.first - b.second;
});
for (int i = 1; i <= s; i++)
{
ans += a[i].second;
S.insert(a[i].second);
}
for (int i = s + 1; i <= s + k; i++)
K.PB(a[i]);
for (int i = s + k + 1; i <= n; i++)
{
ans += a[i].first;
M.insert(a[i].first);
}
while (!K.empty())
{
LL x = K.back().first, y = K.back().second;
K.pop_back();
LL d1 = -1, d2 = -1;
if (!M.empty())
d1 = x - (*M.begin());
if (!S.empty())
d2 = y - (*S.begin());
if (max(d1, d2) < 0)
continue;
if (d1 > d2)
{
M.erase(M.begin());
M.insert(x);
ans += d1;
}
else
{
S.erase(S.begin());
S.insert(y);
ans += d2;
}
}
cout << ans << endl;
return 0;
}
/*
2
BB
1000 1003
1000 1000
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |