답안 #536173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536173 2022-03-12T14:34:56 Z timreizin Garage (IOI09_garage) C++17
100 / 100
2 ms 256 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> r(n), w(m);
    for (int &i : r) cin >> i;
    for (int &i : w) cin >> i;
    vector<int> slots(n);
    int res = 0;
    queue<int> q;
    for (int i = 0; i < 2 * m; ++i)
    {
        int c;
        cin >> c;
        if (c > 0)
        {
            bool place = false;
            for (int j = 0; j < n; ++j)
            {
                if (slots[j] == 0)
                {
                    res += w[c - 1] * r[j];
                    slots[j] = c;
                    place = true;
                    break;
                }
            }
            if (!place) q.push(c);
        }
        else
        {
            for (int j = 0; j < n; ++j)
            {
                if (slots[j] == -c)
                {
                    if (!q.empty())
                    {
                        slots[j] = q.front();
                        q.pop();
                        res += w[slots[j] - 1] * r[j];
                    }
                    else slots[j] = 0;
                    break;
                }
            }
        }
    }
    cout << res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 220 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct