#include <bits/stdc++.h>
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
using namespace std;
#define int long long
#define ll long long
#define xx first
#define yy second
#define all (x) begin(x), end(x)
int n, m;
const int NMAX = 1e5 + 10;
int v[NMAX], w[NMAX], ans[NMAX];
int sum;
queue <int> pq;
signed main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++ i){
cin >> v[i];
}
for (int i = 1; i <= m; ++ i){
cin >> w[i];
}
for (int i = 0; i < 2 * m; ++ i){
int x;
cin >> x;
if (x > 0)
pq.push(x);
else{
for (int i = 1; i <= n; ++ i){
if (ans[i] == -x){
ans[i] = 0;
}
}
}
for (int i = 1; i <= n; ++ i){
if (!pq.empty() && ans[i] == 0){
ans[i] = pq.front();
pq.pop();
sum += w[ans[i]] * v[i];
}
}
}
cout << sum;
return 0 ^ 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2504 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2528 KB |
Output is correct |