Submission #488622

# Submission time Handle Problem Language Result Execution time Memory
488622 2021-11-19T18:51:46 Z Alexandruabcde Garage (IOI09_garage) C++14
100 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 105;
constexpr int MMAX = 2005;

int N, M;
int ans = 0;

int R[NMAX], W[MMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 1; i <= N; ++ i )
        cin >> R[i];

    for (int i = 1; i <= M; ++ i )
        cin >> W[i];
}

int occ[MMAX];
priority_queue <int, vector <int>, greater<int> > H;
queue <int> Q;

void Solve () {
    int ans = 0;
    for (int i = 1; i <= N; ++ i )
        H.push(i);

    for (int event = 1; event <= 2 * M; ++ event ) {
        int x;
        cin >> x;

        if (x > 0)
            Q.push(x);
        else
            H.push(occ[-x]);

        while (!Q.empty() && !H.empty()) {
            int car = Q.front();
            Q.pop();
            int park = H.top();
            H.pop();

            ans += W[car] * R[park];
            occ[car] = park;
        }
    }

    cout << ans << '\n';
}

int main () {
    Read();
    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 268 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct