Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long t[1000001]={};
- long long n,wyn=0;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>t[i];
- }
- reverse(t+1,t+n+1);
- for(int i=2;i<=n;i++)
- {
- if(t[i]>t[i-1])
- {
- if(t[i-1]>t[i+1])
- {
- wyn++;
- t[i]=t[i-1]-1;
- }
- else
- {
- cout<<"-1";
- return 0;
- }
- }
- }
- cout<<wyn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement