-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1044.cpp
More file actions
33 lines (32 loc) · 783 Bytes
/
1044.cpp
File metadata and controls
33 lines (32 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
int n, m, sum[100010] = {0}, in, minsub = INT_MAX;
vector<pair<int, int>> ans;
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>in;
sum[i] = sum[i-1] + in;
}
for(int i=1; i<=n; i++){
int left = i, right = n, mid;
while(left < right){
mid = (left + right) / 2;
if(sum[mid] - sum[i-1] >= m) right = mid;
else left = mid + 1;
}
int sub = sum[left] - sum[i-1] - m;
if(sub >= 0 && sub < minsub){//×¢ÒâÏÞÖÆsub>=0
minsub = sum[left]-sum[i-1]-m;
ans.clear();
ans.push_back(make_pair(i, left));
}else if(sub >= 0 && sub == minsub){//×¢ÒâÏÞÖÆsub>=0
ans.push_back(make_pair(i, left));
}
}
for(auto &pa : ans){
cout<<pa.first<<'-'<<pa.second<<endl;
}
return 0;
}