#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m, a[110], b[2100], ans;
int curPos[2100];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
set<int> av;
for (int i = 1; i <= n; i++){
cin >> a[i];
av.insert(i);
}
for (int i = 1; i <= m; i++)
cin >> b[i];
queue <int> q;
for (int i = 1; i <= m+m; i++){
int x;
cin >> x;
if (x > 0){
q.push(x);
} else {
av.insert(curPos[-x]);
}
while(!av.empty() && !q.empty()){
int guy = q.front();
q.pop();
int pos = *av.begin();
av.erase(av.begin());
curPos[guy] = pos;
ans += a[pos]*b[guy];
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
3 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
3 ms |
756 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
4 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
772 KB |
Output is correct |
14 |
Correct |
3 ms |
808 KB |
Output is correct |
15 |
Correct |
3 ms |
836 KB |
Output is correct |
16 |
Correct |
3 ms |
836 KB |
Output is correct |
17 |
Correct |
3 ms |
1016 KB |
Output is correct |
18 |
Correct |
4 ms |
1016 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
4 ms |
1016 KB |
Output is correct |