fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, x;
  6. cin>>n>>x;
  7. int i, y;
  8. long long nr=0;
  9. for(i=2;i<=n;i++)
  10. {
  11. cin>>y;
  12. if(y>=x)
  13. nr+=y-x;
  14. x=y;
  15. }
  16. cout<<nr;
  17. return 0;
  18. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty