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>
#define ll long long
using namespace std;
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
ll answ = 0;
for(int i = 0; i < n; i++) {
multiset<ll> a;
ll sum = 0;
for(int j = i; j < start; j++)
a.insert(attraction[j]), sum += attraction[j];
for(int j = start; j < n; j++) {
a.insert(attraction[j]);
sum += attraction[j];
ll enrg = d - min(2 * (j - start) + (start - i), (j - start) + 2 * (start - i));
if(enrg < 0)break;
auto it = prev(a.end());
ll cum = 0;
enrg = min(enrg, (ll)a.size());
while(enrg--) {
cum += *it;
it = prev(it);
}
answ = max(answ, cum);
}
}
return answ;
}
/*
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;
}
/*
5 2 7
10 2 20 30 1
*/
Compilation message (stderr)
holiday.cpp:42:1: warning: "/*" within comment [-Wcomment]
42 | /*
|
# | 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... |