#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
ll n,m,i,cst[101],w[2001],pos[2001],x,ans;
priority_queue<int>pq;
deque<int>v;
int main (){
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>cst[i];
pq.push(-i);
}
for(i=1;i<=m;i++) cin>>w[i];
for(i=1;i<=2*m;i++){
cin>>x;
if(x>0){
if(v.size()) v.pub(x);
else {
if(pq.size()==0) v.pub(x);
else{
ll o=-pq.top();
pos[x]=o;
ans+=w[x]*cst[o];
pq.pop();
}
}
}
else{
pq.push(-pos[-x]);
if(v.size()){
ll o=-pq.top();
pos[v.front()]=o;
ans+=w[v.front()]*(cst[o]);
pq.pop();
v.pop_front();
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
3 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
3 ms |
632 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
908 KB |
Output is correct |
16 |
Correct |
4 ms |
908 KB |
Output is correct |
17 |
Correct |
5 ms |
908 KB |
Output is correct |
18 |
Correct |
4 ms |
960 KB |
Output is correct |
19 |
Correct |
5 ms |
960 KB |
Output is correct |
20 |
Correct |
5 ms |
960 KB |
Output is correct |