Cod sursa(job #1519853)
| Utilizator | Data | 7 noiembrie 2015 22:14:49 | |
|---|---|---|---|
| Problema | Operatii | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#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()
{
long long 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;
}
