Submission #267936

# Submission time Handle Problem Language Result Execution time Memory
267936 2020-08-16T07:16:26 Z hhh07 Garage (IOI09_garage) C++14
100 / 100
4 ms 512 KB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int, int> ii;

int main(){
    int n, m;
    cin >> n >> m;
    int w[m], r[n];
    priority_queue<int> rq;
    for (int i = 0; i < n; i++){
        cin >> r[i];
        rq.push(-(i + 1));
    }
    for (int i = 0; i < m; i++)
        cin >> w[i];

    int x[2*m];
    for (int i = 0; i < 2*m; i++)
        cin >> x[i];

    queue<int> q;

    int car[m];
    int val = 0;
    for (int i = 0; i < 2*m; i++){
        if (x[i] > 0)
            q.push(x[i] - 1);
        else
            rq.push(-(car[-x[i] - 1] + 1));
        
        while(!rq.empty()){
            if (q.empty())
                break;
            int x = rq.top();
            int y = q.front();
            q.pop(); rq.pop();
            val += w[y]*r[- x - 1];
            //cout << w[y] << " " << r[- x - 1] << endl;
            car[y] = - x - 1;
        }
    }
    cout << val << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct