#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define pb push_back
#define INF 100000000
#define mp make_pair
ll n,m,ans = 0,x;
ll r[101];
ll w[2001];
ll pos[2001];
ll status[101];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
fill(pos,pos+m+1,0);
fill(status,status+n+1,0);
for (int i = 1; i <= n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> w[i];
queue<int> q;
for (int lol = 0; lol < 2*m; lol++){
cin >> x;
if (x > 0){
if (!q.empty()) q.push(x);
else{
bool f = true;
for (int i = 1; i <= n; i++){
if (!status[i]){
f = false;
status[i] = x;
pos[x] = i;
ans += w[x]*r[i];
break;
}
}
if (f) q.push(x);
}
}
else{
x = -x;
status[pos[x]] = 0;
if (!q.empty()){
int next = q.front();
q.pop();
status[pos[x]] = next;
pos[next] = pos[x];
ans += w[next]*r[pos[next]];
}
pos[x] = 0;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |