Pagini recente » Cod sursa (job #2348854) | Cod sursa (job #3193982) | Cod sursa (job #2877274) | Cod sursa (job #1238476) | Cod sursa (job #1586649)
#include <fstream>
using namespace std;
ifstream fin("operatii.in");
ofstream fout("operatii.out");
long long motorization(int n, long long last, int now, long long sum) {
long long x;
fin >> x;
++now;
if (last < x) {
sum += x - last;
last = x;
if (now != n)
return motorization(n, last, now, sum);
}
if (now == n)
return sum;
last = x;
return motorization(n, last, now, sum);
}
int main()
{
int n;
fin >> n;
fout << motorization(n, 0, 0, 0);
return 0;
}