Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6. int array[n+1];
  7. array[n]=0;
  8. for(int i=0;i<n;i++){
  9. cin>>array[i];
  10. }
  11. int cont=0;
  12. int finale=1;
  13. int o=0;
  14. int s;
  15. while(finale==1){
  16. s=o+1;
  17. while(array[s]>0||array[o]>0){
  18. array[s]--;
  19. s++;
  20. }
  21. if(array[o]>0)
  22. cont++;
  23. array[o]--;
  24. if(array[o]<1)
  25. o++;
  26. if(o==n-1&&array[o]==0)
  27. finale=0;
  28. }
  29. cout<<cont;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement