Pagini recente » Istoria paginii utilizator/ucv_barbulescu_dobre_feraru | Cod sursa (job #853928) | Cod sursa (job #2169362) | Cod sursa (job #1273344) | Cod sursa (job #1519852)
#include <bits/stdc++.h>
#define nmax 1000005
using namespace std;
ifstream fin("operatii.in");
ofstream fout("operatii.out");
int n;
int a[nmax];
int main()
{
int i, s, cnt;
fin >> n;
s = 0;
for(i = 1; i <= n; i++)
{
fin >> a[i];
s += a[i];
}
cnt = 0;
while(s > 0)
{
cnt++;
for(i = 1; i <= n ; )
{
while(a[i] == 0) i++;
while(a[i] != 0)
{
s--;
a[i]--;
i++;
}
i = n + 2;
}
}
fout << cnt;
return 0;
}