Cod sursa(job #206732)
| Utilizator | Data | 9 septembrie 2008 11:15:43 | |
|---|---|---|---|
| Problema | Operatii | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.41 kb |
#include<stdio.h>
const int maxn = 1000200;
int N,ST[maxn];
int main()
{
freopen("operatii.in","r",stdin);
freopen("operatii.out","w",stdout);
scanf("%d\n",&N);
long long sol = 0;
for(int i = 1;i <= N; ++i)
{
int x = 0;
scanf("%d",&x);
if (ST[ST[0]] < x)
{
sol += (long long)-(ST[ST[0]] - x);
}
while(ST[ST[0]] < x && ST[0]) ST[0]--;
ST[++ST[0]] = x;
}
printf("%lld\n",sol);
return 0;
}
