Submission #313374

# Submission time Handle Problem Language Result Execution time Memory
313374 2020-10-15T22:26:01 Z fergonzgut21 Garage (IOI09_garage) C++14
100 / 100
4 ms 384 KB
#include <iostream>
#include <queue>
#define MAX 105
#define MAX2 2005
using namespace std;

int N, M, A[MAX], res, B[MAX2], a, num, C[MAX2];
priority_queue <int> qiu;
queue <int> qiu2;

int main()
{
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        qiu.push(i * -1);
    }
    for (int i = 1; i <= M; i++)
        cin >> B[i];
    for (int i = 1; i <= M * 2; i++)
    {
        cin >> a;
        if (a > 0)
        {
            if (qiu.empty())
                qiu2.push(a);
            else
            {
                C[a] = qiu.top() * -1;
                res += A[qiu.top() * -1] * B[a];
                qiu.pop();
            }
        }
        else
        {
            qiu.push(C[a * -1] * -1);
            if (!qiu2.empty())
            {
                a = qiu2.front();
                qiu2.pop();
                C[a] = qiu.top() * -1;
                res += A[qiu.top() * -1] * B[a];
                qiu.pop();
            }
        }
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 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 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct