Cod sursa(job #2785232)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 18 octombrie 2021 11:47:55
Problema Operatii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.36 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("operatii.in");
ofstream fout("operatii.out");

const int nmax = 1000005;
int n, v[nmax];
int main(){
    fin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; ++i){
        fin >> v[i];
        if (v[i] > v[i - 1]) ans += (v[i] - v[i - 1]);
    }
    fout << ans;
    return 0;
}