#include <bits/stdc++.h>
using namespace std;
#define int long long
int rate[100],par[100],weight[2001],alloted[2001],n;
deque<int> waiting;
int find(int x,int y){
if (x == par[x]){
par[x] = x+1;
return x;
}
if (x == n-1){
waiting.push_back(y);
return -1;
}
return find(par[x],y);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,m,x,cur;
// cin >> t;
while (t--){
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> rate[i];
par[i] = i;
}
for (int i = 1; i <= m; i++){
cin >> weight[i];
}
int ans = 0;
for (int i = 0; i < 2*m; i++){
cin >> x;
//x--;
if (x < 0){
x = abs(x);
par[alloted[x]] = alloted[x];
if (!waiting.empty()){
cur = waiting.front();
alloted[cur] = find(0,cur);
waiting.pop_front();
ans += (weight[cur]*rate[alloted[cur]]);
}
}
else {
cur = find(0,x);
if (cur == -1){
continue;
}
alloted[x] = cur;
ans += (weight[x]*rate[cur]);
}
}
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |