Cod sursa(job #2712466)

Utilizator tomaionutIDorando tomaionut Data 25 februarie 2021 19:47:04
Problema Operatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.35 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("operatii.in");
ofstream fout("operatii.out");
int n,x;
long long sol;
int main()
{	
	int i,cnt=0;
	fin >> n;
	for (i = 1; i <= n; i++)
	{
		fin >> x;
		if (x == 0)
		{
			sol += cnt;
			cnt = 0;
		}
		else cnt = max(cnt, x);

	}
	sol += cnt;
	fout << sol;


	return 0;
}