답안 #176001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
176001 2020-01-07T14:17:32 Z emil_physmath 학교 설립 (IZhO13_school) C++17
95 / 100
269 ms 20828 KB
// #define DEBUG
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef long long llong;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, aNum, bNum;
    cin >> n >> aNum >> bNum;
    struct City
    {
        int a, b;
    };
    vector<City> cities(n);
    for (int i = 0; i < n; ++i)
        cin >> cities[i].a >> cities[i].b;
    sort(cities.begin(), cities.end(), [](const City& lhs, const City& rhs) {
         return lhs.a - lhs.b > rhs.a - rhs.b;
    });
    vector<long long> pref(n, -30'000'000'000LL), suff(n, -30'000'000'000LL);
    multiset<int> a;
    long long sum = 0;
    for (int i = 0; i < aNum; ++i)
    {
        a.insert(cities[i].a);
        sum += cities[i].a;
    }
    pref[aNum - 1] = sum;
    for (int i = aNum; i < n; ++i)
    {
        sum += cities[i].a;
        a.insert(cities[i].a);
        sum -= *a.begin();
        a.erase(a.begin());
        pref[i] = sum;
    }
    sum = 0;
    multiset<int> b;
    for (int i = 1; i <= bNum; ++i)
    {
        b.insert(cities[n - i].b);
        sum += cities[n - i].b;
    }
    suff[n - bNum] = sum;
    for (int i = bNum + 1; i <= n; ++i)
    {
        sum += cities[n - i].b;
        b.insert(cities[n - i].b);
        sum -= *b.begin();
        b.erase(b.begin());
        suff[n - i] = sum;
    }
    long long ans = 0;
    for (int i = 0; i + 1 < n; ++i)
        ans = max(ans, pref[i] + suff[i + 1]);
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 636 KB Output is correct
13 Correct 28 ms 3192 KB Output is correct
14 Correct 50 ms 4632 KB Output is correct
15 Correct 75 ms 6132 KB Output is correct
16 Correct 193 ms 15164 KB Output is correct
17 Correct 211 ms 17016 KB Output is correct
18 Correct 214 ms 17016 KB Output is correct
19 Correct 241 ms 18552 KB Output is correct
20 Correct 269 ms 20828 KB Output is correct