Pagini recente » Cod sursa (job #639545) | Rating Ionut Deaconu (dcmionut) | Cod sursa (job #2764372) | Cod sursa (job #633090) | Cod sursa (job #176443)
Cod sursa(job #176443)
#include <cstdio>
#include <vector>
#define vv 100005
using namespace std;
int n,last1,prec1,max1,last2,prec2,max2,last3,prec3,max3;
vector <int> v;
void citire()
{
freopen("oo.in","r",stdin);
scanf("%d", &n);
int w;
for (int i=1; i<=n; i++)
{
scanf("%d", &w);
v.push_back(w);
}
}
void rezolvare()
{
//a1[1]=v[0]+v[1];
last1=1;
prec1=max1=v[0]+v[1];
last2=2;
prec2=max2=v[1]+v[2];
last3=0;
prec3=max3=v[n-1]+v[0];
int w=0;
for (int i=2; i<n; i++)
{
w=v[i]+v[i-1];
if (i-last1>2 && i!=n-1)
{
max1+=w;
last1=i;
prec1=w;
}
else if (i-last1==1 && max1-prec1+w>max1 && i!=n-1)
{
max1-=prec1;
max1+=w;
last1=i;
prec1=w;
}
//////////////////////////////////////////
if (i-last2>2)
{
max2+=w;
last2=i;
prec2=w;
}
else if (i-last2==1 && max2-prec2+w>max2)
{
max2-=prec2;
max2+=w;
last2=i;
prec2=w;
}
//////////////////////////////////////////
if (i-last3>2 && i!=n-1 && i!=n-2)
{
max3+=w;
last3=i;
prec3=w;
}
else if (i-last3==1 && max3-prec3+w>max3 && i!=n-1 && i!=n-2)
{
max3-=prec3;
max3+=w;
last3=i;
prec3=w;
}
}
//freopen("oo.out","w",stdout);
if (max1>=max2 && max1>=max3)
printf("%d\n",max1);
else
if (max2>=max1 && max2>=max3)
printf("%d\n",max2);
else
if (max3>=max2 && max3>=max1)
printf("%d\n",max3);
}
int main()
{
citire();
rezolvare();
return 0;
}