Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long t[1000001]={};
  4. long long n,wyn=0;
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. cin>>n;
  11. for(int i=1;i<=n;i++)
  12. {
  13. cin>>t[i];
  14. }
  15. reverse(t+1,t+n+1);
  16. for(int i=2;i<=n;i++)
  17. {
  18. if(t[i]>t[i-1])
  19. {
  20. if(t[i-1]>t[i+1])
  21. {
  22. wyn++;
  23. t[i]=t[i-1]-1;
  24. }
  25. else
  26. {
  27. cout<<"-1";
  28. return 0;
  29. }
  30. }
  31. }
  32. cout<<wyn;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement