-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1044.cpp
More file actions
27 lines (25 loc) · 787 Bytes
/
1044.cpp
File metadata and controls
27 lines (25 loc) · 787 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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> nums(n), sums(n + 1);
for (int i = 0; i < n; i++)
cin >> nums[i];
for (int i = 1; i <= n; i++)
sums[i] = sums[i-1] + nums[i-1];
int near_sum = sums.back();
for (auto i = sums.begin(); i != sums.end(); i++) {
auto j = lower_bound(i + 1, sums.end(), *i + m);
if (j != sums.end())
near_sum = min(*j - *i, near_sum);
}
for (auto i = sums.begin(); i != sums.end(); i++) {
auto j = lower_bound(i + 1, sums.end(), *i + near_sum);
if (j != sums.end() && *j - *i == near_sum)
printf("%d-%d\n", i - sums.begin() + 1, j - sums.begin());
}
return 0;
}