#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
int r[2001];
int w[2001];
int s[2002];
int vis[2001];
int res =0;
int n , m;
int main(){
cin >> n;
cin >>m;
memset(vis , 0 , sizeof(vis));
vector<int> wait;
for(int i = 1; i<=n; i++){
cin >> r[i];
}
for(int i = 1; i<=m; i++){
cin >> w[i];
}
for(int i = 1; i<=m * 2; i++){
int tmp;
cin >> tmp;
if(tmp > 0){
bool flag =true;
for(int i = 1; i<=n; i++){
if(vis[i] == 0){
res+=r[i] * w[tmp];
vis[i] = tmp;
flag = false;
break;
}
}
if(flag) wait.pb(tmp);
}
else {
int sul = -1;
for(int i = 1; i<=n; i++){
if(vis[i] == tmp * (-1)){
vis[i] = 0;
sul = i;
break;
}
}
if(wait.size()!=0 ) {
res+=w[wait[0]] * r[sul];
vis[sul] = wait[0];
wait.erase(wait.begin());
}
}
}
cout << res << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |