#include <iostream>
#include <queue>
#include <assert.h>
using namespace std;
int N, M, A[101], B[2001];
int where[2001], filled[101], to = 0;
queue<int> q;
int res = 0;
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < M; i++)
{
where[i] = -1;
cin >> B[i];
}
for (int k = 0; k < 2 * M; k++)
{
int i; cin >> i;
if (i > 0)
{
i--;
if (to == N) {q.push(i);}
else
{
to++;
for (int j = 0; j < N; j++)
{
if (!filled[j]) {res += A[j] * B[i]; filled[j] = 1; where[i] = j; break;}
}
}
}
else
{
i = -i; i--;
filled[where[i]] = 0; to--;
if (q.size())
{
to++;
filled[where[i]] = 1; where[q.front()] = where[i];
res += A[where[i]] * B[q.front()]; q.pop();
}
}
}
cout << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |