Submission #1103483

# Submission time Handle Problem Language Result Execution time Memory
1103483 2024-10-21T04:04:40 Z overwatch9 Garage (IOI09_garage) C++17
100 / 100
2 ms 596 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector <int> rate(n);
    for (int i = 0; i < n; i++)
        cin >> rate[i];
    vector <int> wt(m+1);
    multiset <int> available;
    for (int i = 1; i <= m; i++)
        cin >> wt[i];
    for (int i = 0; i < n; i++)
        available.insert(i);
    vector <int> occ(m+1);
    queue <int> q;
    int ans = 0;
    for (int i = 0; i < 2 * m; i++) {
        int x;
        cin >> x;
        if (x > 0) {
            if (available.empty())
                q.push(x);
            else {
                occ[x] = *available.begin();
                available.erase(available.begin());
                ans += wt[x] * rate[occ[x]];
            }
        } else {
            x = -x;
            if (!q.empty()) {
                ans += rate[occ[x]] * wt[q.front()];
                occ[q.front()] = occ[x];
                q.pop();
            } else {
                available.insert(occ[x]);
            }
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 500 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct