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. if(x != 0)
  10. nr++;
  11.  
  12. for(i=2;i<=n;i++)
  13. {
  14. cin>>y;
  15. if(y>=x)
  16. nr+=y-x;
  17. x=y;
  18. }
  19. cout<<nr;
  20. return 0;
  21. }
Success #stdin #stdout 0s 15240KB
stdin
5
1 0 3 1 2
stdout
5