#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll modexp(ll b, ll e, ll m){
ll r = 1;
while(e > 0){
if((e & 1) == 1){
r = (r * b) % m;
}
e >>= 1;
b = (b * b) % m;
}
return r;
}
bool isvowel(char ch) {
return (ch == 'a') || (ch == 'e') ||(ch == 'i') ||(ch == 'o') ||(ch == 'u') ||(ch == 'y');
}
int main() {
int n, m;
cin >> n >> m;
vector<int> rates;
for(int i = 0; i < n; i++) {
int v;
cin >> v;
rates.push_back(v);
}
vector<int> cars;
for(int i = 0; i < m; i++) {
int v;
cin >> v;
cars.push_back(v);
}
vector<int> space(n, -1);
vector<int> car_to_space(n, -1);
int ans = 0;
queue<int> q;
for(int i = 0; i < m * 2; i++) {
int v;
cin >> v;
if(v > 0) {
v--;
bool found = false;
for(int j = 0; j < n; j++) {
if(space[j] == -1) {
space[j] = v;
car_to_space[v] = j;
ans += rates[j] * cars[v];
found = true;
// cout << "~~~ " << v << " " << j << endl;
break;
}
}
if(!found)
q.push(v);
} else {
v = abs(v) - 1;
// cout << "!!! " << v << " " << car_to_space[v] << endl;
space[car_to_space[v]] = -1;
if(!q.empty()) {
space[car_to_space[v]] = q.front();
car_to_space[q.front()] = car_to_space[v];
ans += rates[car_to_space[v]] * cars[q.front()];
q.pop();
}
car_to_space[v] = -1;
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
400 KB |
Execution killed with signal 6 |
5 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
8 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
9 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
10 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
12 |
Runtime error |
1 ms |
428 KB |
Execution killed with signal 6 |
13 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
14 |
Runtime error |
1 ms |
424 KB |
Execution killed with signal 6 |
15 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
16 |
Runtime error |
2 ms |
444 KB |
Execution killed with signal 6 |
17 |
Runtime error |
2 ms |
416 KB |
Execution killed with signal 6 |
18 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
19 |
Runtime error |
2 ms |
424 KB |
Execution killed with signal 11 |
20 |
Runtime error |
3 ms |
460 KB |
Execution killed with signal 6 |