Pagini recente » Cod sursa (job #2260340) | Cod sursa (job #1463114) | Cod sursa (job #60893) | Cod sursa (job #759934) | Cod sursa (job #49680)
Cod sursa(job #49680)
#include <stdio.h>
#define Real(i) ((A[i])+(A[i-1]))
#define maxa(a,b) (((a) > (b)) ? (a) : (b))
#define maxim(a,b,c) (maxa(maxa(a,b),maxa(b,c)))
int i,j,n,m,A[100],B[100],S[100],REZ;
void ReadData(void)
{
int i;
freopen("oo.in","r",stdin);
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&A[i]);
B[i]=Real(i);
}
}
void Emptyy(int S[])
{
int i;
for (i=1;i<=n;i++)
S[i]=0;
}
int DL(int l, int r)
{
int i,max=0;
Emptyy(S);
S[l]=B[l]; S[l+1]=B[l+1]; S[l+2]=B[l+2];
for (i=l+3;i<=r;i++)
{
S[i]=max+B[i];
if (S[i-3] > max)
max = S[i-3];
}
max=0;
for (i=l;i<=r;i++)
if (S[i]>max)
max=S[i];
return max;
}
void Solve(void)
{
int a1,a2,a3;
a1=DL(3,n-2)+B[1];
a2=DL(1,n-1);
a3=DL(2,n);
REZ=maxim(a1,a2,a3);
}
void PrintData(void)
{
freopen("oo.out","w",stdout);
printf("%d\n",REZ);
}
int main()
{
ReadData();
Solve();
PrintData();
/*dbxfklhasdkl;gft;sdjg'jsdgsdfjhgl'sdfjgh'
sd';sldfjghlsjgl;sdgksd
gjsdf'jg
';sdjgh;p
jsdf;
ghjsdjg';sfjghp
jsdfg'
jsdf;ghjscg;
sdjkgh
sdfjgh';sd;jsf'ghj
sdgjl'sdfjg'lsdfjg'sdj';jsd
hgjsd'gj;
sdj;
sdjgh';sdjg';sdjh;
'sdhj
sd;jgh'lsdj'ghj
sdf;hj';
sdfjh;
sdfjh;
sdfjkh;
js;
hj;
sfjkh;sfjh;
sfjh'
sdjh'
sdfj
hj */
return 0;
}