Cod sursa(job #2474269)

Utilizator eugen5092eugen barbulescu eugen5092 Data 14 octombrie 2019 22:07:36
Problema Operatii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;
ifstream ci("operatii.in");
ofstream cou("operatii.out");
int n,v[1000003];

int main()
{
int i,dif,x,y;
long long cn,n;
ci>>n;
/*
for(i=1;i<=n;i++ ){
 ci>>v[i];
}

for(i=0;i<=n-1;i++){
    dif=v[i+1]-v[i];
    if(dif>0 ){cn+=dif; }
}


*/
if(n==1){ci>>x;cou<<x;}else{
ci>>x>>y;
//dif=x
cn+=x;
dif=y-x;
if(dif>0 ){cn+=dif; }
n-=2;
while(n--){
    x=y;
    ci>>y;
    dif=y-x;
    if(dif>0 ){cn+=dif; }

}


cou<<cn;
}

}