이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include<bits/stdc++.h>
using namespace std;
priority_queue<long long int> caso2;
long long int tabla_izq[250001],tabla_der[250001];
int valores[100000];
int ini=0;
int lim=0;
int lim_c;
long long int avanzar_der(int dia,int i,long long int acum=0){
if(dia>lim||i>=lim_c) return 0;
long long int aux=acum+valores[i];
aux+=tabla_izq[lim-dia-(i-ini)];
aux=max(aux,avanzar_der(dia+1,i+1,acum));
aux=max(aux,avanzar_der(dia+2,i+1,acum+valores[i]));
return aux;
}
void t_i(int dia,int i,long long int acum=0){
if(dia>lim||i<0) return;
tabla_izq[dia]=max(acum+valores[i],tabla_izq[dia]);
t_i(dia+1,i-1,acum);
t_i(dia+2,i-1,acum+valores[i]);
}
long long int avanzar_izq(int dia,int i,long long int acum=0){
if(dia>lim||i<0) return 0;
long long int aux=acum+valores[i];
aux+=tabla_der[lim-dia-(ini-i)];
aux=max(aux,avanzar_izq(dia+1,i-1,acum));
aux=max(aux,avanzar_izq(dia+2,i-1,acum+valores[i]));
return aux;
}
void t_d(int dia,int i,long long int acum=0){
if(dia>lim||i>=lim_c) return;
tabla_der[dia]=max(acum+valores[i],tabla_der[dia]);
t_d(dia+1,i+1,acum);
t_d(dia+2,i+1,acum+valores[i]);
}
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
lim=d;
lim_c=n;
ini=start;
long long int res=0;
if(start==0){
long long int aux=0;
for(int i=0;i<n;i++){
if(d==0){
aux-=(caso2.top()*-1);
caso2.pop();
d++;
}
aux+=attraction[i];
res=max(res,aux);
caso2.push(attraction[i]*-1);
d--;
if(d==0){
aux-=(caso2.top()*-1);
caso2.pop();
}
else d--;
}
}
else{
for(int i=0;i<n;i++){
valores[i]=attraction[i];
}
t_i(2,start-1);
res=avanzar_der(1,start);
t_d(2,start+1);
res=max(res,avanzar_izq(1,start));
}
return res;
}
# | 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... |