Cod sursa(job #2540484)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 7 februarie 2020 11:16:27
Problema Operatii Scor 100
Compilator cpp-64 Status done
Runda irim_eralumis Marime 0.56 kb
#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;
}