#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(m, -1);
ll 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;
int s = car_to_space[v];
space[s] = -1;
if(!q.empty()) {
int c = q.front();
q.pop();
space[s] = c;
car_to_space[c] = s;
ans += rates[s] * cars[c];
}
car_to_space[v] = -1;
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |