SHARE
TWEET

Untitled

a guest Dec 8th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top