Submission #501347

# Submission time Handle Problem Language Result Execution time Memory
501347 2022-01-02T20:43:19 Z Iwanttobreakfree Garage (IOI09_garage) C++17
100 / 100
2 ms 336 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
    int n,m,x,ans=0;
    cin>>n>>m;
    vector<int> r(n),w(m),park(m,-1);
    for(int& i:r)cin>>i;
    for(int& i:w)cin>>i;
    queue<int> q;
    priority_queue<int> pq;
    for(int i=0;i<n;i++)pq.push(-i);
    for(int i=0;i<2*m;i++){
        cin>>x;
        if(x<0){
            x*=-1;
            x--;
            pq.push(-park[x]);
            ans+=w[x]*r[park[x]];
            park[x]=-1;
            if(!q.empty()){
                park[q.front()]=-pq.top();
                pq.pop();
                q.pop();
            }
        }
        else{
            x--;
            if(pq.empty())q.push(x);
            else{
                park[x]=-pq.top();
                pq.pop();
            }
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 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 1 ms 332 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 2 ms 300 KB Output is correct
20 Correct 2 ms 332 KB Output is correct