Submission #963072

#TimeUsernameProblemLanguageResultExecution timeMemory
963072coolboy19521Garage (IOI09_garage)C++17
100 / 100
2 ms2652 KiB
# include <bits/stdc++.h>

namespace ddr {
    # define bpc(bt) __builtin_popcountll(bt)
    # define bcl(bt) __builtin_clz(bt)
    # define alr(v) rbegin(v), end(v)
    # define all(v) begin(v), end(v)
    # define si(v) ((ll)v.size())
    # define mp make_pair
    # define pb push_back
    # define ins insert
    # define se second
    # define fi first

    template <class T, class U> using pi = std::pair <T, U>;
    template <class T> using pq = std::priority_queue <T>;
    template <class T> using mt = std::multiset <T>;
    template <class T> using ve = std::vector <T>;
    template <class T> using qu = std::queue <T>;
    typedef std::string str;
    typedef long long ll;
    typedef bool bo;
    typedef char ch;

    using namespace std;

    const ll inf = 1e18 + 18;
}

using namespace ddr;

const ll sz = 3e5 + 15;

ll n, m, c, i, j;
ll r[sz], w[sz];

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);

    cin >> n >> m;

    for (i = 1; i <= n; i ++) {
        cin >> r[i];
    }

    for (i = 1; i <= m; i ++) {
        cin >> w[i];
    }

    map <ll, ll> t;
    pq <ll> p;
    qu <ll> q;

    for (i = 1; i <= n; i ++) {
        p.push(-i);
    }

    c = 0;

    for (i = 0; i < 2 * m; i ++) {
        ll a;
        cin >> a;

        if (a > 0) {
            if (!p.empty()) {
                t[a] = p.top();
                p.pop();

                c += w[a] * r[-t[a]];
            } else {
                q.push(a);
            }
        } else {
            p.push(t[-a]);

            if (!q.empty()) {
                ll a = q.front();
                q.pop();

                t[a] = p.top();
                p.pop();

                c += w[a] * r[-t[a]];
            }
        }
    }

    cout << c;
}
#Verdict Execution timeMemoryGrader output
Fetching results...