Cod sursa(job #123055)
| Utilizator | Data | 14 ianuarie 2008 15:20:48 | |
|---|---|---|---|
| Problema | Operatii | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.37 kb |
#include<stdio.h>
long x[1000005],i,j,k,n,l,s;
int main()
{
freopen("operatii.in","r",stdin);
freopen("operatii.out","w",stdout);
scanf("%ld",&n);
for (i=1;i<=n;i++)
scanf("%ld",&x[i]);
for (i=1;i<=n;i++)
{
j=i;
while (x[j]<=x[j+1]&&j<=n) j++;
s+=(x[j]-k);
while (x[j]>=x[j+1]&&j<=n) j++;
k=x[j];
i=j-1;
}
printf("%ld\n",s);
return 0;
}