#include <bits/stdc++.h>
using namespace std;
int w[2001], p[101], loc[2001];
set<int> pos;
queue<int> q;
int main(){
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; i++){
cin>>p[i];
pos.insert(i);
}
for(int i = 1; i <= m; i++){
cin>>w[i];
}
for(int i = 1; i <= 2 * m; i++){
int k;
cin>>k;
if(k > 0) q.push(k);
else pos.insert(loc[-k]);
while(pos.size() && !q.empty()){
int a = *pos.begin();
loc[q.front()] = a;
pos.erase(pos.begin());
q.pop();
}
}
long long ans = 0;
for(int i = 1; i <= m; i++){
ans += (long long)w[i] * p[loc[i]];
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |