Submission #761225

# Submission time Handle Problem Language Result Execution time Memory
761225 2023-06-19T11:18:58 Z Blagoj Garage (IOI09_garage) C++17
100 / 100
2 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int n, m, t;
    cin >> n >> m;
    t = n;
    int r[n], w[m], went[m];
    for (int i = 0; i < n; i++) cin >> r[i];
    for (int i = 0; i < m; i++) cin >> w[i];
    queue<int> q;
    bool full[n];
    memset(full, 0, sizeof(full));
    ll ans = 0;
    for (int i = 0; i < 2 * m; i++) {
        int c;
        cin >> c;
        if (c > 0) {
            c--;
            if (n == 0) {
                q.push(c);
                continue;
            }
            for (int j = 0; j < t; j++) {
                if (full[j]) continue;
                ans += w[c] * r[j];
                full[j] = 1;
                went[c] = j;
                n--;
                break;
            }
        }
        else {
            c *= -1;
            c--;
            n++;
            full[went[c]] = 0;
            while (n > 0 && q.size() > 0) {
                int f = q.front();
                q.pop();
                for (int j = 0; j < t; j++) {
                    if (full[j]) continue;
                    ans += w[f] * r[j];
                    full[j] = 1;
                    went[f] = j;
                    n--;
                    break;
                }
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 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