Submission #100772

# Submission time Handle Problem Language Result Execution time Memory
100772 2019-03-14T09:39:43 Z Alexa2001 Garage (IOI09_garage) C++17
100 / 100
5 ms 412 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e4 + 5;

int n, m, x, i;
queue<int> q;
priority_queue< int, vector<int>, greater<int> > heap;
int coef[Nmax], w[Nmax], where[Nmax];
long long ans = 0;

int main()
{
   // freopen("input", "r", stdin);

    cin >> n >> m;
    for(i=1; i<=n; ++i) cin >> coef[i];
    for(i=1; i<=m; ++i) cin >> w[i];

    for(i=1; i<=n; ++i) heap.push(i);

    for(i=1; i<=2*m; ++i)
    {
        cin >> x;

        if(x > 0) q.push(x);
            else heap.push(where[-x]);

        while(q.size() && heap.size())
        {
            x = q.front();
            where[x] = heap.top();
            ans += w[x] * coef[where[x]];
            q.pop(); heap.pop();
        }
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 412 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct