Cod sursa(job #1494558)

Utilizator ionut98Bejenariu Ionut Daniel ionut98 Data 1 octombrie 2015 13:33:44
Problema Oo Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<fstream>
using namespace std;
ifstream f("oo.in");
ofstream g("oo.out");
int c1[100001],c2[100001],c3[100001],s1,s2,s3,i,j,k,n;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>c1[i];
        c2[i]=c3[i]=c1[i];
    }
    s1=c1[1]+c1[2];
    c1[n]=c1[1]=c1[2]=c1[3]=0;
    for(i=4;i<=n;i+=j)
    {
        if(c1[i]+c1[i+1]>=c1[i+1]+c1[i+2])
        {
            s1+=c1[i]+c1[i+1];
            j=3;
        }
        else
        {
            s1+=c1[i+1]+c1[i+2];
            j=4;
        }
    }
    s2=c2[2]+c2[3];
    c2[1]=c2[2]=c2[3]=c2[4]=0;
    for(i=5;i<=n;i+=j)
    {
        if(c2[i]+c2[i+1]>=c2[i+1]+c2[i+2])
        {
            s2+=c2[i]+c2[i+1];
            j=3;
        }
        else
        {
            s2+=c2[i+1]+c2[i+2];
            j=4;
        }
    }
    s3=c3[n]+c3[1];
    c3[1]=c3[2]=c3[n-1]=c3[n]=0;
    for(i=3;i<=n;i+=j)
    {
        if(c3[i]+c3[i+1]>=c3[i+1]+c3[i+2])
        {
            s3+=c3[i]+c3[i+1];
            j=3;
        }
        else
        {
            s3+=c3[i+1]+c3[i+2];
            j=4;
        }
    }
    g<<max(max(s1,s2),s3);
    return 0;
}