Cod sursa(job #130545)
| Utilizator | Data | 1 februarie 2008 15:13:39 | |
|---|---|---|---|
| Problema | Operatii | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<stdio.h>
long v[(1<<20)];
int main()
{
freopen("operatii.in","r",stdin);
freopen("operatii.out","w",stdout);
long n;
scanf("%ld",&n);
long max = 0 , h = 0;
long long sol = 0;
for( long i = 1; i <= n; ++i )
{
scanf("%ld",&v[i]);
if( v[i] > max) max = v[i];
if( v[i] < v[i-1]) { sol+= (max-v[i]); max = v[i];}
}
sol+=max;
printf("%lld\n",sol);
}
