Cod sursa(job #2915203)

Utilizator alin.gabrielAlin Gabriel Arhip alin.gabriel Data 22 iulie 2022 01:48:32
Problema Operatii Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
#include <string>
using namespace std;

long long findMax(int *v, int n) {
    int lmax = 0;
    long long gmax = 0;

    for (int i = 1; i < n; i++) {
        if (lmax > v[i])
            gmax += lmax - v[i];
        lmax = v[i];
    }

    gmax += lmax;

    return gmax;
}

int main() {
    ifstream fin("operatii.in");
    ofstream fout("operatii.out");
    
    int n;
    fin >> n;

    int v[n];
    for (int i = 0; i < n; i++)
        fin >> v[i];
 
    fout << findMax(v, n);

    return 0;
}