Submission #220415

# Submission time Handle Problem Language Result Execution time Memory
220415 2020-04-07T21:06:32 Z tatyam Garage (IOI09_garage) C++17
100 / 100
6 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(b) for(int i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> r(n), w(m);
    each(i, r) cin >> i;
    each(i, w) cin >> i;
    int ans = 0;
    vector<int> park(m);
    priority_queue<int, vector<int>, greater<int>> space;
    queue<int> q;
    rep(n) space.push(i);
    rep(m * 2){
        int a;
        cin >> a;
        if(a < 0){
            if(q.size()){
                int at = park[~a];
                a = q.front();
                q.pop();
                park[a] = at;
                ans += r[at] * w[a];
            }
            else space.push(park[~a]);
        }
        else{
            a--;
            if(space.size()){
                int at = space.top();
                space.pop();
                park[a] = at;
                ans += r[at] * w[a];
            }
            else q.push(a);
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct