# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171744 | davitmarg | 학교 설립 (IZhO13_school) | C++17 | 277 ms | 18556 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, k;
LL ans, pr[N], sf[N];
pair<LL, LL> a[N];
multiset<LL> s;
int main()
{
cin >> n >> m >> k;
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 <= n; i++)
{
pr[i] = pr[i - 1] + a[i].first;
s.insert(a[i].first);
if (s.size() > m)
{
pr[i] -= (*s.begin());
s.erase(s.begin());
}
}
s.clear();
for (int i = n; i >= 1; i--)
{
sf[i] = sf[i + 1] + a[i].second;
s.insert(a[i].second);
if (s.size() > k)
{
sf[i] -= (*s.begin());
s.erase(s.begin());
}
}
for (int i = 1; i <= n; i++)
ans = max(pr[i] + sf[i + 1], ans);
cout << ans << endl;
return 0;
}
/*
3 1 1
100 0
100 50
0 20
4 1 1
100 0
550 500
500 550
0 100
3 1 1
100 0
500 550
0 100
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |