#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
void solve(){
int n,m;
cin>>n>>m;
vector<int>r(n);
for(int&i:r)
cin>>i;
vector<int>w(m);
for(int&i:w)
cin>>i;
vector<int>e(2*m);
for(int&i:e)
cin>>i;
int res=0;
vector<int>parked(n,-1);
int timer=0;
queue<int>q;
for(int event:e){
if(event>0){
event--;
bool par=false;
for(int i=0;i<n;i++){
if(parked[i]==-1){
parked[i]=event;
par=true;
break;
}
}
if(!par)
q.push(event);
}else{
event=-event-1;
for(int i=0;i<n;i++){
if(parked[i]==event){
parked[i]=-1;
res+=r[i]*w[event];
if(q.size()){
parked[i]=q.front();
q.pop();
}
}
}
}
timer++;
}
cout<<res<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
/*
3 4
2
3
5
200
100
300
800
3
2
-3
1
4
-4
-2
-1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
372 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |