Pagini recente » Cod sursa (job #3263863) | Cod sursa (job #2171149) | Cod sursa (job #2457126) | Cod sursa (job #1018313) | 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;
}