Cod sursa(job #2915209)

Utilizator alin.gabrielAlin Gabriel Arhip alin.gabriel Data 22 iulie 2022 02:25:17
Problema Operatii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>
using namespace std;

int main() {
    ifstream fin("operatii.in");
    ofstream fout("operatii.out"); 
    
    int n, x;
    int lmax = 0;
    long long gmax = 0;
    fin >> n;
    for (int i = 0; i < n; i++) {
        fin >> x;
        if (lmax > x)
            gmax += lmax - x;
        lmax = x;
    }

    gmax += lmax;
    fout << gmax;

    fin.close();
    fout.close();
    return 0;
}