Advertisement
Guest User

Untitled

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