Advertisement
Guest User

chujciwdupe

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int szuflady[1000000];
  5. int n;
  6. int ilWsunietych=0;
  7.  
  8. int main()
  9. {
  10.  
  11. cin>>n;
  12. for(int i=0; i<n; i++){
  13. cin>>szuflady[i];
  14. }
  15.  
  16. n--;
  17. while(n>0)
  18. {
  19. if(szuflady[n]<=szuflady[n-1]){
  20. szuflady[n-1]=szuflady[n]-1;
  21. ilWsunietych++;
  22. }
  23.  
  24. n--;
  25. }
  26.  
  27.  
  28. if(szuflady[0]>0){
  29. cout<<ilWsunietych;
  30. }
  31.  
  32. else
  33. {
  34. cout<<"-1";
  35. }
  36.  
  37.  
  38.  
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement