Problem——A. Reverse a Substring——Codeforces

You are given a string s consisting of n lowercase Latin letters.

Let’s define a substring as a contiguous subsegment of a string. For example, “acab” is a substring of “abacaba” (it starts in position 3 and ends in position 6), but “aa” or “d” aren’t substrings of this string. So the substring of the string s from position l to position r is s[l;r]=slsl+1…sr.

You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l;r]=srsr−1…sl) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.

If it is impossible to reverse some substring of the given string to obtain a string that is less, print “NO”. Otherwise print “YES” and any suitable substring.

String x is lexicographically less than string y, if either x is a prefix of y (and x≠y), or there exists such i (1≤i≤min(|x|,|y|)), that xi<yi, and for any j (1≤j<i) xj=yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

Input

The first line of the input contains one integer n (2≤n≤3⋅105) — the length of s.

The second line of the input contains the string s of length n consisting only of lowercase Latin letters.

Output

If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print “NO”. Otherwise print “YES” and two indices l and r (1≤l<r≤n) denoting the substring you have to reverse. If there are multiple answers, you can print any.

Examples

inputCopy

7
abacaba

outputCopy

YES
2 5

inputCopy

6
aabcfg

outputCopy

NO

Note

In the first testcase the resulting string is “aacabba”.

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define dd double
#define mes(x,y) memset(x,y,sizeof(y))
using namespace std;
int main(){
	int n;
	while(cin>>n){
			string s;cin>>s;
			getchar();
			int begin,end,flag=0;
			for(int i=0;i<s.length()-1;i++){
				if(s[i]>s[i+1]){
					begin=i+1;
					end=i+2;
					flag=1;
					break;
				} 
			}
			if(flag==1){
				cout<<"YES"<<endl;
				cout<<begin<<" "<<end<<endl;
			}
			else if(flag==0){
				cout<<"NO"<<endl;
			}
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值