#include <bits/stdc++.h>
using namespace std;
int n, m, a[102], b[2003], c[2003], fp;
queue<int> q;
bool d[102];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
for(int i = 1; i <= m; ++i) {
cin >> b[i];
}
for(int mi = 1; mi <= 2 * m; ++mi) {
int x;
cin >> x;
if(x < 0) {
x = -x;
d[c[x]] = 0;
if(q.size()) {
c[q.front()] = c[x];
d[c[q.front()]] = 1;
fp += a[c[q.front()]] * b[q.front()];
q.pop();
}
} else {
for(int i = 1; i <= n; ++i) {
if(!d[i]) {
c[x] = i;
d[c[x]] = 1;
fp += a[c[x]] * b[x];
break;
}
}
if(!c[x]) {
q.push(x);
}
}
}
cout << fp << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |