#include<cstdio>#include<algorithm>usingnamespace std;constint nmax =100001;int a[nmax], s[nmax], n, m;intmain(){scanf("%d%d",&n,&m);for(int i =1; i <= n; i++){scanf("%d",&a[i]);
s[i]= s[i -1]+ a[i];}int min=100000001, j;for(int i =1; i <= n; i++){
j =lower_bound(s + i, s + n +1, s[i -1]+ m)- s;if(s[j]- s[i -1]< min && j != n +1) min = s[j]- s[i -1];}int cnt =0;for(int i =1; i <= n; i++){
j =lower_bound(s + i, s + n +1, s[i -1]+ m)- s;if(s[j]- s[i -1]== min){if(!cnt) cnt++;elseprintf("\n");printf("%d-%d", i, j);}}return0;}
1044 Shopping in Mars解题代码测试结果问题整理解题代码#include<cstdio>#include<algorithm>using namespace std;const int nmax = 100001;int a[nmax], s[nmax], n, m;int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d",