#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
set<int> st;
queue<int> qq;
int c[110];
int w[2010];
int t[2010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>c[i];
st.insert(i);
}
for(int i=1;i<=m;i++)
cin>>w[i];
for(int i=1;i<=2*m;i++)
{
int x;
cin>>x;
if(x>0)
qq.push(x);
while(!qq.empty() && !st.empty())
{
ans+=w[qq.front()]*c[*st.begin()];
t[qq.front()]=*st.begin();
st.erase(st.begin());
qq.pop();
}
if(x<0)
st.insert(t[-x]);
}
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
368 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |