Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
int S[300005],T[4];
double M[300005];
int main(){
scanf("%d",&n);
for(int i=0;i<3;i++){
scanf("%d",&T[i]);
}
sort(T,T+3);
for(int i=0;i<n;i++){
scanf("%d",&S[i]);
}
double a,b,c;
for(int i=0;i<n;i++){
if(M[i]!=0 || i==0){
a=b=c=0;
for(int e=0;e<T[0] && e+i<=n;e++)
a+=S[e+i];
b=a;
for(int e=T[0];e<T[1] && e+i<=n;e++)
b+=S[e+i];
c=b;
for(int e=T[1];e<T[2] && e+i<=n;e++)
c+=S[e+i];
a=(double)a/(double)T[0];
b=(double)b/(double)T[1];
c=(double)c/(double)T[2];
if(i+T[0]<=n)
M[i+T[0]]=max(M[i]+a,M[i+T[0]]);
if(i+T[1]<=n)
M[i+T[1]]=max(M[i]+b,M[i+T[1]]);
if(i+T[2]<=n)
M[i+T[2]]=max(M[i]+c,M[i+T[2]]);
}
}
if(M[n]>0)
printf("%0.2f\n",M[n]);
else
printf("Lo siento amigo\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.