Pagini recente » Cod sursa (job #3368897) | Cod sursa (job #3367894) | Cod sursa (job #3368243) | Rating Oprea Rares (Oprea_Rares) | Cod sursa (job #3367347)
// 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;
}