362B - Petya and Staircases - CodeForces Solution


implementation sortings *1100

Please click on ads to support us..

Python Code:

n, m = tuple(map(int, input().split()))
if m>0:
    arr = list(map(int, input().split()))
    arr.sort()
    ans = "YES"
    cnt = 0
    if (n in arr) or (1 in arr):
        ans = "NO"
    else:
        for i in range(1,m):
            if arr[i]-arr[i-1]==1:
                cnt+=1
            else:
                cnt=0
            if cnt==2:
                ans = "NO"
                break
    print(ans)
else:
    print("YES")

C++ Code:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const long long MOD = 1e9  , OO = 1e18;
const double PI = acos(-1);
const int N = 1e5 + 5;

void solve()
{
    ll n,m,c=0,mx=0,f=0;
    cin >> n >> m;
    ll a[m];
    for(ll i=0 ; i < m ; i++)
        cin >>a[i];
    sort(a,a+m);
    for(ll i=0 ; i < m-1 ; i++){
        if(a[i+1]-a[i]==1)c++;
        else c=0;
        mx=max(mx,c);
    }
    for(ll i=0 ; i < m ; i++){
        if(a[i]==1 || a[i]==n){
            f=1;
            break;
        }
    }
    if(mx>=2 || f )cout<<"NO";
    else cout<<"YES";

    return;
}

int main()
{    
    IO
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
        cout<<"\n";
    }
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci