Codeforces Round #258 (Div. 2) 451B - Sort the Array Solution


 
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t,n,i,l=0,r=0;
    cin>>n;
    int a[n+9],b[n+9];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(i=0; i<n; i++)
        if(a[i]!=b[i])
        {
            l=i;
            break;
        }
    for(i=n-1; i>=0; i--)
        if(a[i]!=b[i])
        {
            r=i;
            break;
        }
    reverse(a+l,a+r+1);
    for(i=0; i<n; i++)
        if(a[i]!=b[i])
        {
            cout<<"no"<<"\n";
            return 0;
        }
    printf("yes\n%d %d\n",l+1,r+1);
    return 0;
}


No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.