#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int n,m;
cin >> n >> m;
int r[n],w[m];
for(int i=0;i<n;i++)cin >> r[i];
for(int i=0;i<m;i++)cin >> w[i];
ll ans = 0;
int space[n];
memset(space,-1,sizeof(space));
queue<int> q;
for(int i=0;i<2*m;i++){
int a;
cin >> a;
if(a<0){
a*=-1;
a--;
int index = 0;
for(int j=0;j<n;j++)if(space[j]==a)index = j;
space[index]=-1;
}else{
a--;
q.push(a);
}
if(q.empty())continue;
int index = -1;
for(int j=0;j<n;j++)
if(space[j]==-1){
index =j;
break;
}
if(index!=-1){
//cout << index+1 << "\t" << q.front()+1 << "\n";
space[index]=q.front();
ans += r[index]*w[q.front()];
q.pop();
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
372 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
3 ms |
364 KB |
Output is correct |