Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, licznik = 0;
- cin >> n;
- int tab[n];
- for(int i = 0; i < n; ++i)
- cin >> tab[i];
- if(n == 1)
- {
- cout << 0;
- return 0;
- }
- for(int i = n-2; i >= 0; --i)
- {
- if(tab[i] >= tab[i+1])
- {
- tab[i] = tab[i+1] - 1;
- ++licznik;
- if(tab[i] == 0)
- {
- cout << -1;
- return 0;
- }
- }
- }
- cout << licznik;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement