#include<iostream>
using namespace std;
typedef long long LL;
#define maxn 100010
LL rec[maxn] = {0};
int main(){
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> rec[i];
for(int i = 2; i <= n; i++) rec[i] = rec[i] + rec[i - 1];
int min = rec[n];
for(int i = 1; i <= n; i++){
int pos = lower_bound(rec + i, rec + n + 1, m + rec[i - 1]) - rec;
if(pos != n + 1 && rec[pos] - rec[i - 1] < min) min = rec[pos] - rec[i - 1];
}
for(int i = 1; i <= n; i++){
int pos = lower_bound(rec + i, rec + n + 1, m + rec[i - 1]) - rec;
if(pos != n + 1 && rec[pos] - rec[i - 1] == min)
printf("%d-%d\n", i, pos);
}
return 0;
}
几点关于lower_bound的注意事项
- 是小于等于
- end取不到
- 如果找不到返回的是end;