| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 47562 | fallingstar | 학교 설립 (IZhO13_school) | C++17 | 459 ms | 13164 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.
/**
    Problem: Schools
    Source: IX Zhautykov Olympiad on Mathematics, Physics and Informatics (IZhO) 2013, day 1, problem C
*/
#include <iostream>
#include <algorithm>
#include <set>
#define long long long
using namespace std;
const int N = 3e5 + 2;
int n, m1, m2;
pair<int, int> a[N];
long fa[N], fb[N];
int main()
{
    cin >> n >> m1 >> m2;
    for (int i = 1; i <= n; ++i)
        cin >> a[i].first >> a[i].second;
    sort(a + 1, a + 1 + n, [](pair<int, int> a, pair<int, int> b) {
        return a.first - a.second > b.first - b.second;
    });
    set<pair<int, int> > s;
    for (int i = 1; i <= n; ++i)
    {
        fa[i] = fa[i - 1] + a[i].first;
        s.insert({a[i].first, i});
        if (s.size() > m1)
        {
            fa[i] -= s.begin()->first;
            s.erase(s.begin());
        }
    }
    s.clear();
    for (int i = n; i >= 1; --i)
    {
        fb[i] = fb[i + 1] + a[i].second;
        s.insert({a[i].second, i});
        if (s.size() > m2)
        {
            fb[i] -= s.begin()->first;
            s.erase(s.begin());
        }
    }
    long res = 0;
    for (int i = m1; i + m2 <= n; ++i)
        res = max(res, fa[i] + fb[i + 1]);
    cout << res;
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
