Cod sursa(job #2456432)

Utilizator TheNextGenerationAyy LMAO TheNextGeneration Data 14 septembrie 2019 12:59:27
Problema Operatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("operatii.in");
ofstream out("operatii.out");


int main()
{
    int n, Max=0;
    long long cnt = 0;
    in >> n;
    for (int i = 1; i<=n; i++)
    {
        int x;
        in >> x;
        if (!x)
        {
            cnt+=Max;
            Max = 0;
        }
        else
            Max = max(Max,x);
    }
    cnt+=Max;
    out << cnt;
}