#include<iostream>
#include<vector>
using namespace std;
int main()
{
int N,M,a[100000];
int i,j,Sum;
vector<int>left,right;
cin>>N>>M;
for(i=0;i<N;i++)cin>>a[i];
int minbigger=2000000000;
for(i=j=0,Sum=0;j<N||Sum>=M;){
if(Sum<M){
Sum+=a[j];
j++;
}
else if(Sum>M){
if(Sum<minbigger)minbigger=Sum;
Sum-=a[i];
i++;
}
else{
left.emplace_back(i+1);
right.emplace_back(j);
Sum-=a[i];
i++;
}
}
if(left.size()){
for(i=0;i<left.size();i++){
cout<<left[i]<<'-'<<right[i]<<endl;
}
return 0;
}
M=minbigger;
for(i=j=0,Sum=0;j<N||Sum>=M;){
if(Sum<M){
Sum+=a[j];
j++;
}
else if(Sum>M){
if(Sum<minbigger)minbigger=Sum;
Sum-=a[i];
i++;
}
else{
left.emplace_back(i+1);
right.emplace_back(j);
Sum-=a[i];
i++;
}
}
if(left.size()){
for(i=0;i<left.size();i++){
cout<<left[i]<<'-'<<right[i]<<endl;
}
return 0;
}
}
1044 Shopping in Mars
最新推荐文章于 2024-08-29 16:39:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)