Cod sursa(job #3367347)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 7 octombrie 2026 10:21:25
Problema Operatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
// https://infoarena.ro/problema/operatii

#include <bits/stdc++.h>

using namespace std;

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

const int NRMAX = 1000000;

int v[NRMAX + 5];

int main()
{
    int n, i, maxi, rez = 0;

    fin >> n;
    for (i = 1; i <= n; ++i) {
        fin >> v[i];
        //cout << v[i] << " ";
    }
    //cout << "\n";

    i = 1;
    while(i <= n) {
        maxi = 0;
        //cout << "INCEPUT SECVENTA ";
        //cout << i << "\n";
        while (i <= n && v[i]) {
            maxi = max(maxi, v[i]);
            ++i;
        }
        //cout << "FINAL SECVENTA ";
        //cout << i << "\n";
        //cout << maxi << "\n";

        rez += maxi;

        while(i <= n && !v[i]) {
            ++i;
        }
    }

    fout << rez << "\n";

    return 0;
}