#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define int ll
using namespace std;
const int N = 2e3 + 5;
int val[N],w[N],p[N];
queue <int> q;
set <int> st;
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++){
st.insert(i);
cin>>val[i];
}
for (int i=1;i<=m;i++)
cin>>w[i];
int ans=0;
for (int i= 1;i<=2*m;i++){
int x;
cin>>x;
if(x > 0){
q.push(x);
}else{
st.insert(p[-x]);
}
while (st.size() && q.size()){
int x = q.front(),id = *st.begin();
q.pop();
p[x] = id;
ans += val[id] * w[x];
st.erase(st.begin());
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |