Cod sursa(job #949574)

Utilizator vlady1997Vlad Bucur vlady1997 Data 14 mai 2013 11:18:19
Problema Oo Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
        #include <cstdio>
        #include <cstring>
        using namespace std;
        int a[100001], b[100001], c[100001];
        int max (int x, int y)
        {
            if (x>=y) return x;
            else return y;
        }
        int main()
        {
            int n, i;
            freopen("oo.in","r",stdin);
            freopen("oo.out","w",stdout);
            scanf("%d",&n); memset(b,0,sizeof(b)); memset(c,0,sizeof(c));
            for (i=1; i<=n; i++) scanf("%d",&a[i]);
            for (i=2; i<=n; i++)
            {
                if (i!=n)
                {
                    b[i]=max(a[i-1]+a[i]+b[i-3],b[i-1]);
                }
                c[i]=max(b[i-1],c[i-1]);
            }
            printf("%d",c[n]);
            fclose(stdin);
            fclose(stdout);
            return 0;
        }