Pagini recente » Cod sursa (job #1177693) | Cod sursa (job #2869448) | Cod sursa (job #2227431) | Cod sursa (job #538812) | Cod sursa (job #1586633)
#include <fstream>
using namespace std;
ifstream fin("operatii.in");
ofstream fout("operatii.out");
void motorization(int n) {
long long mx = 0, sum = 0;
for (int i = 1; i <= n; ++i) {
long long x;
fin >> x;
if (x == 0) {
sum += mx;
mx = 0;
continue;
}
(mx < x)? mx = x: true;
if (i == n)
sum += mx;
}
fout << sum;
}
int main()
{
int n;
fin >> n;
motorization(n);
return 0;
}