Cod sursa(job #935081)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 1 aprilie 2013 15:11:48
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("oo.in"); ofstream fout("oo.out");

long sol, oo[122206], a[122206], n, s1, s2, s3;


int main()
{
  fin >> n;
  long i;
  for(i = 1; i <= n; ++i)
      fin >> oo[i];

  if(n>2)
   {

  a[2] = oo[1] + oo[2];

  for(i = 3; i <= n; ++i) a[i]=max(oo[i] + oo[i - 1] + a[i - 3], a[i - 1]);

  s1 = a[n - 1];

  for(i = 0; i <= n; ++i) a[i] = 0;

  for(i = 3; i <= n; ++i)

     a[i] = max(oo[i] + oo[i - 1] + a[i - 3], a[i - 1]);

  s2 = a[n];

  for(i = 0; i <= n; ++i) a[i] = 0;

  a[1] = a[2] = oo[1] + oo[n];

  for(i = 3; i < n - 1; ++i) a[i] = max(oo[i] + oo[i - 1] + a[i - 3], a[i - 1]);

  s3 = a[n - 2];

   }

  else
    {
    s1 = oo[1] + oo[0],
    s2 = s1,
    s3 = s1;
    }

  sol = max(max(s1, s2), s3);

    fout << sol;

  return 0;
  }