Cod sursa(job #2210416)

Utilizator Raresr14Rosca Rares Raresr14 Data 6 iunie 2018 17:46:06
Problema Oo Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.34 kb
#include <fstream>
using namespace std;
ifstream fin("oo.in");
ofstream fout("oo.out");
int n,i,D[100100],v[100100],maxim;
int main(){
    fin>>n;
    for(i=1;i<=n;i++)
        fin>>v[i];
    D[1]=0;
    D[2]=0;
    D[3]=v[2]+v[3];
    for(i=4;i<=n;i++)
        D[i]=max(v[i-1]+v[i]+D[i-3],D[i-1]);
    fout<<D[n];
    return 0;
}