#include <bits/stdc++.h>
using namespace std;
long long s = 0;
int n, m, a, fr, val;
vector<int> w;
vector<int> r;
vector<int> parks;
int enter(int x){
for (int i = 0; i < n; i++){
if (parks[i] == -1){
parks[i] = x;
s += w[x - 1] * r[i];
fr--;
return 0;
}
}
return 0;
}
int ex(int x){
for (int i = 0; i < n; i++){
if (parks[i] == x){
parks[i] = -1;
fr++;
return 0;
}
}
return 0;
}
int main(){
cin>>n>>m;
fr = n;
for (int i = 0; i < n; i++){
cin>>a;
r.push_back(a);
parks.push_back(-1);
}
for (int i = 0; i < m; i++){
cin>>a;
w.push_back(a);
}
queue<int> ord;
for (int i = 0; i < 2 * m; i++){
cin>>a;
if (a > 0){
ord.push(a);
}
else{
ex(-a);
}
while (!ord.empty() && fr > 0){
val = ord.front();
ord.pop();
enter(val);
}
}
cout<<s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
684 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
680 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 |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
380 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |