Cod sursa(job #3141148)

Utilizator beauty_in_the_skyPlesu Iulia beauty_in_the_sky Data 12 iulie 2023 20:23:19
Problema Operatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.41 kb

#include <bits/stdc++.h>
#define llu long long unsigned
using namespace std;


int main()
{
    ifstream fin("operatii.in");
    ofstream fout("operatii.out");
    int n, lmax = 0, nr = 0, x;
    fin >> n;
    for (int i = 1; i <= n; ++i)
    {
        fin >> x;
        if (x > lmax)
            lmax = x;
        if (x == 0 || i == n)
            nr += lmax, lmax = 0;
    }
    fout << nr;
}