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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
ll solve(int N, int S, int D, int A[]) {
ll res = 0;
for(int l = S; ~l && D; l--, D--) {
priority_queue<int, vector<int>, greater<int>> pq;
ll ans = 0, cur = 0;
for(int i = l; i < N; i++) {
pq.push(A[i]); cur += A[i];
while(pq.size() + i - l > D) {
if(pq.empty()) break;
cur -= pq.top(); pq.pop();
}
ans = max(ans, cur);
}
res = max(res, ans);
}
return res;
}
ll findMaxAttraction(int N, int start, int D, int attraction[]) {
ll A = solve(N, start, D, attraction);
reverse(attraction, attraction + N);
start = N - start - 1;
ll B = solve(N, start, D, attraction);
return max(A, B);
}
Compilation message (stderr)
holiday.cpp: In function 'll solve(int, int, int, int*)':
holiday.cpp:21:49: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
21 | while(pq.size() + i - l > 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... |