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
const int maxn = 1e5 + 5;
int n;
int a[maxn];
int solve(int s, int d) {
int ans = 0, curans = 0;
priority_queue<int, vector<int>, greater<int>> pq;
for (int i=s;i<=n;i++) {
pq.push(a[i]), curans += a[i];
while (pq.size() > 0 && i-s + pq.size() > d) {
curans -= pq.top();
pq.pop();
}
ans = max(curans, ans);
}
return ans;
}
int findMaxAttraction(int32_t N, int32_t S, int32_t d, int32_t A[]) {
n = N, S++;
for (int i=1;i<=n;i++) a[i] = A[i-1];
int ans = 0;
for (int i=S, D=d;i>=1;i--, D--) ans = max(solve(i, D), ans);
reverse(a+1, a+n+1); S = n+1-S;
for (int i=S, D=d;i>=1;i--, D--) ans = max(solve(i, D), ans);
return ans;
}
Compilation message (stderr)
holiday.cpp: In function 'long long int solve(long long int, long long int)':
holiday.cpp:14:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
14 | while (pq.size() > 0 && i-s + pq.size() > d) {
| ~~~~~~~~~~~~~~~~^~~
# | 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... |