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