#include "bits/stdc++.h"
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int occ[n];
memset(occ, 0, sizeof occ);
int coe[n], where[m];
for (int i=0; i<n; i++) {
cin >> coe[i];
}
int wgt[m];
for (int i=0; i<m; i++) {
cin >> wgt[i];
where[i] = -1;
}
int sm = 0;
queue<int> wait;
for (int i=0; i<2*m; i++) {
int nxt;
cin >> nxt;
bool inc = true;
if (nxt < 0) {
inc = false;
nxt = -nxt;
}
nxt--;
if (inc) {
wait.push(nxt);
}
else {
int at = where[nxt];
occ[at] = false;
}
bool can = !wait.empty();
for (int j=0; j<n && can; j++) {
if (!occ[j]) {
occ[j] = true;
int c = wait.front(); wait.pop();
sm += wgt[c] * coe[j];
where[c] = j;
}
can = !wait.empty();
}
}
cout << sm << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
252 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |