Submission #11329171


Source Code Expand

Copy
#include <bits/stdc++.h>

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> pv(A), qv(B);
    REP(i, A) {
        cin >> pv[i];
    }
    REP(i, B) {
        cin >> qv[i];
    }
    priority_queue<int> r;
    REP(i, C) {
        int v;
        cin >> v;
        r.push(v);
    }

    RSORT(pv);
    RSORT(qv);

    priority_queue<int, vector<int>, greater<int>> p, q;
    REP(i, X) {
        p.push(pv[i]);
    }
    REP(i, Y) {
        q.push(qv[i]);
    }

    ll ans = 0;
    while(0 != X || 0 != Y) {
        auto fetch = [&](auto& pq) {
                         if(pq.top() < r.top() && !r.empty()) {
                             ans += r.top();
                             r.pop();
                         }
                         else {
                             ans += pq.top();
                         }
                         pq.pop();
                     };
        if((p.top() < q.top() && 0 != X) || Y == 0) {
            fetch(p);
            X--;
        }
        else {
            fetch(q);
            Y--;
        }
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Red and Green Apples
User medalotte
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2468 Byte
Status
Exec Time 69 ms
Memory 2552 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 Sample_01.txt, Sample_02.txt, Sample_03.txt
All 500 / 500 Sample_01.txt, Sample_02.txt, Sample_03.txt, case_01.txt, case_03.txt, case_05.txt, case_07.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt, case_19.txt, case_20.txt, case_21.txt, case_22.txt, case_23.txt, case_24.txt, case_25.txt, case_26.txt, case_27.txt
Case Name Status Exec Time Memory
Sample_01.txt 1 ms 256 KB
Sample_02.txt 1 ms 256 KB
Sample_03.txt 1 ms 256 KB
case_01.txt 67 ms 2552 KB
case_03.txt 66 ms 2552 KB
case_05.txt 67 ms 2552 KB
case_07.txt 52 ms 1784 KB
case_09.txt 52 ms 1784 KB
case_10.txt 52 ms 1784 KB
case_11.txt 64 ms 2552 KB
case_12.txt 63 ms 2552 KB
case_13.txt 69 ms 2552 KB
case_15.txt 61 ms 2552 KB
case_16.txt 45 ms 1660 KB
case_17.txt 44 ms 1660 KB
case_18.txt 1 ms 256 KB
case_19.txt 1 ms 256 KB
case_20.txt 35 ms 1660 KB
case_21.txt 38 ms 1404 KB
case_22.txt 44 ms 1784 KB
case_23.txt 23 ms 1024 KB
case_24.txt 43 ms 1788 KB
case_25.txt 39 ms 1532 KB
case_26.txt 33 ms 1532 KB
case_27.txt 36 ms 1404 KB