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;
typedef long long ll;
const int MAXN = (int) 4e5 + 5;
ll dp1[MAXN][2], dp2[MAXN][2];
ll findMaxAttraction(int n, int start, int d, int attraction[]) {
memset(dp1, 0, sizeof(dp1));
memset(dp2, 0, sizeof(dp2));
multiset<ll> st;
for(int j = start; j >= 0; j--){
st.insert(attraction[j]);
int cnt = 0;
ll top = 0;
for(auto u = st.rbegin(); u != st.rend(); u++){
cnt++;
top += *u;
dp1[start - j + cnt][1] = max(dp1[start - j + cnt][1], top);
dp1[2*(start - j) + cnt][0] = max(dp1[2*(start - j) + cnt][0], top);
}
}
st.clear();
for(int j = start + 1; j < n; j++){
st.insert(attraction[j]);
int cnt = 0;
ll top = 0;
for(auto u = st.rbegin(); u != st.rend(); u++){
cnt++;
top += *u;
dp2[j - start + cnt][1] = max(dp2[j - start + cnt][1], top);
dp2[2*(j - start) + cnt][0] = max(dp2[2*(j - start) + cnt][0], top);
}
}
for(int i = 1; i <= d; i++){
dp1[i][0] = max(dp1[i - 1][0], dp1[i][0]);
dp1[i][1] = max(dp1[i][1], dp1[i - 1][1]);
dp2[i][0] = max(dp2[i - 1][0], dp2[i][0]);
dp2[i][1] = max(dp2[i][1], dp2[i - 1][1]);
}
ll ans = 0;
for(int i = 0; i <= d; i++){
ans = max(ans, dp1[i][0] + dp2[d - i][1]);
ans = max(ans, dp1[d - i][1] + dp2[i][0]);
}
return ans;
}
/*ll findMaxAttraction1(int n, int start, int d, int attraction[]){
ll ans = 0;
for(int i = 1; i < (1<<n); i++){
int mask = i;
int bas = 0, son = n - 1;
while(!((1<<bas) & mask)) bas++;
while(!((1<<son) & mask)) son--;
int acik = __builtin_popcount(mask);
ll top = 0;
for(int i = bas; i <= son; i++)
if((1<<i) & mask)
top += attraction[i];
if(bas >= start){
if(son - start + acik <= d){
ans = max(ans, top);
}
}else if(son >= start){
int mes1 = son - start, mes2 = start - bas;
if(mes2 < mes1) swap(mes1, mes2);
if(2*mes1 + mes2 + acik <= d)
ans = max(ans, top);
}else{
if(start - bas + acik <= d){
ans = max(ans, top);
}
}
}
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... |