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>
#if !defined(LOL)
#include "holiday.h"
#endif
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define ll long long
ll calc(deque<ll> &a, int d){
ll ans = 0, sum = 0;
multiset<ll> S; S.clear();
for(int i = 0; i < sz(a); i++){
S.insert(a[i]); sum+=(ll)a[i];
int rem = d-i; rem = max(rem,0);
while(sz(S)>rem) sum-=(ll)*S.begin(), S.erase(S.begin());
ans = max(ans, sum);
}
return ans;
}
long long int findMaxAttraction(int n, int s, int d, int a[]) {
deque<ll> v, w; for(int i = s; i < n; i++) v.pb(a[i]);
for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
ll ans = max(calc(v,d),calc(w,d));
for(int i = s-1; i>=0; i--){
v.push_front(a[i]),
ans = max(ans, calc(v,d-s+i));
}
if(s==0) return ans;
for(int i = s+1; i < n; i++){
w.push_front(a[i]),
ans = max(ans, calc(w,d-i+s));
}
return ans;
}
#if defined(LOL)
int main() {
int n, start, d;
int attraction[100000];
int i, n_s;
n_s = scanf("%d %d %d", &n, &start, &d);
for (i = 0 ; i < n; ++i) {
n_s = scanf("%d", &attraction[i]);
}
printf("%lld\n", findMaxAttraction(n, start, d, attraction));
return 0;
}
#endif
Compilation message (stderr)
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:26:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
26 | for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
| ^~~
holiday.cpp:26:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
26 | for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
| ^~~~~~~
# | 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... |