#include <bits/stdc++.h>
using namespace std;
bool app[105];
int a[105], b[2005], c[2005];
int main() {
int n, m, cnt=0;
cin >> n >> m;
for (int i=0; i<n; i++) cin >> a[i];
for (int i=0; i<m; i++) cin >> b[i];
queue<int> waiting;
for (int i=0; i<2*m; i++) {
int x;
cin >> x;
if (x > 0) {
x -= 1;
int p=0;
while (p<n&&app[p]) p++;
if (p==n) waiting.push(x);
else app[p] = true, cnt += a[p] * b[x], c[x] = p;
}
else {
x = -x - 1;
app[c[x]] = false;
if (!waiting.empty()) {
int y = waiting.front();
app[c[x]] = true, cnt += a[c[x]] * b[y], c[y] = c[x];
waiting.pop();
}
}
}
cout << cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |