Cod sursa(job #2915208)
Utilizator | Data | 22 iulie 2022 02:22:29 | |
---|---|---|---|
Problema | Operatii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.45 kb |
#include <fstream>
#include <string>
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;
}