Cod sursa(job #2921444)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 31 august 2022 10:26:51
Problema Operatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream>

using namespace std;

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

int main() {
    int n;
    fin >> n;

    int sol = 0, maxSecv = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        fin >> x;

        if (x != 0)
            maxSecv = max(maxSecv, x);
        else {
            sol += maxSecv;
            maxSecv = 0;
        }
    }
    if (maxSecv != 0)
        sol += maxSecv;

    fout << sol;

    return 0;
}