//solved by Halym2007
#include <bits/stdc++.h>
#define ff first
#define ss second
#define cont continue;
#define sz size()
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 20005;
priority_queue <pair <int, int>, vector<pair <int, int>>, greater<pair <int, int>>> v;
queue <int> q;
int a, b[N], l, n, kl;
int sum;
map <int, vector <pair <int, int>>> m;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n >> kl;
for (int i = 1; i <= n; ++i) {
cin >> a;
v.push({i, a});
}
for (int i = 1; i <= kl; ++i) cin >> b[i];
int jp = 2 * kl;
while (jp--) {
cin >> l;
if (l > 0) q.push(l);
int a1 = 0;
if (q.size()) a1 = q.front();
if (l > 0) {
if (!v.empty()) {
if (q.size()) q.pop();
m[a1].pb ({v.top().first,v.top().second});
v.pop();
}
}else{
l *= -1;
sum += (b[l] * m[l][0].ss);
v.push({m[l][0].ff,m[l][0].ss});
m[l].clear();
if (a1 > 0) {
if (!v.empty()) {
if (q.size()) q.pop();
m[a1].pb ({v.top().first,v.top().second});
v.pop();
}
}
}
}
cout << sum << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
536 KB |
Output is correct |