Submission #973038

# Submission time Handle Problem Language Result Execution time Memory
973038 2024-05-01T12:46:14 Z kiddi Garage (IOI09_garage) C++14
100 / 100
2 ms 388 KB
#include <bits/stdc++.h>
#include <queue>
using namespace std;

int n, m;
int val[101];
int tingd[2001];
map<int, int> hvar;
priority_queue<int> rod;
queue<int> bilar;
int tala;
int svar = 0;

int main() {
    cin >> n >> m;
    for (int x = 1; x < 1+n; x++) {
        cin >> val[x];
        rod.push(-x);
    }
    for (int x = 1; x < 1+m; x++) {
        cin >> tingd[x];
    }
    for (int x = 0; x < m*2; x++) {
        cin >> tala;
        if (tala > 0) {
            if (!rod.empty()) {
                hvar[tala] = abs(rod.top());
                rod.pop();
                //cout << hvar[tala] << ' ' << tala << ' ' << val[hvar[tala]]*tingd[tala] << endl;
                svar += val[hvar[tala]]*tingd[tala];
            }
            else {
                bilar.push(tala);
            }
        }
        else {
            tala = -tala;
            rod.push(-hvar[tala]);
            if (!bilar.empty()) {
                tala = bilar.front();
                bilar.pop();
                hvar[tala] = abs(rod.top());
                rod.pop();
                //cout << "??" << endl;
                svar += val[hvar[tala]]*tingd[tala];
            }
        }
        
    }
    cout << svar << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 388 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct