关键:初始化时预处理,产生sum单调序列,从而转化为二分查找
#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
const int maxn=100010;
int sum[maxn];
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif // LOCAL
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&sum[i]);
sum[i]+=sum[i-1];
}
int ans=100000010;
for(int i=0;i<=n;i++){
int j=lower_bound(sum+i+1,sum+n+1,m+sum[i])-sum;
if(j!=n+1){
ans=min(ans,sum[j]-sum[i]);
}
}
for(int i=0;i<=n;i++){
int j=lower_bound(sum+i+1,sum+n+1,ans+sum[i])-sum;
if(j!=n+1 && sum[j]==sum[i]+ans){
printf("%d-%d\n",i+1,j);
}
}
return 0;
}