This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include"holiday.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
const int N = 1e5;
int n, s, d, a[N];
int findMaxAttraction(signed N, signed S, signed D, signed attraction[]) {
n = N;
s = S;
d = D;
for (int i = 0; i < n; i++) {
a[i] = attraction[i];
}
int ans = 0;
for (int i = 0; i <= s; i++) {
priority_queue<int, vector<int>, greater<int>> pq;
int sum = 0;
int rem = d - (s-i);
vector<int> vt(s-i+1);
for (int j = i; j <= s; j++) {
vt[j-i] = a[j];
}
sort(all(vt));
for (int j = s-i; j >= max(0ll, s-i-rem+1); j--) {
sum += vt[j];
pq.push(vt[j]);
}
rem -= min(rem, s-i+1);
//cerr << i << " " << s << " " << sum << " " << rem << endl;
ans = max(ans, sum);
for (int j = s+1; j < n; j++) {
rem = d - pq.size() - (j-i) - min(s-i, j-s);
//cerr << i << " " << j << " " << sum << " " << rem << endl;
while (rem < 0) {
if (pq.empty()) break;
sum -= pq.top();
pq.pop();
rem++;
}
if (rem) {
sum += a[j];
pq.push(a[j]);
}
else if (pq.top() < a[j]) {
sum -= pq.top();
pq.pop();
sum += a[j];
pq.push(a[j]);
}
ans = max(ans, sum);
}cerr << endl;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |