Pagini recente » Cod sursa (job #1491599) | Cod sursa (job #2662594) | Cod sursa (job #782782) | Cod sursa (job #2343112) | Cod sursa (job #2540484)
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;
int main()
{
freopen("operatii.in","r",stdin);
freopen("operatii.out","w",stdout);
int n , x;
long long sum = 0;
int threshold=0;
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
{
scanf("%d",&x);
if(x > threshold)
{
sum += 1ll*x-1ll*threshold;
threshold = x;
continue;
}
else
threshold = x;
}
printf("%lld\n",sum);
return 0;
}