-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_1044.cpp
More file actions
51 lines (47 loc) · 888 Bytes
/
Copy pathA_1044.cpp
File metadata and controls
51 lines (47 loc) · 888 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cstdio>
const int maxn = 100010;
int sum[maxn];
int n, S, nearS = 1000000010;
int upper_bound(int l, int r, int x)
{
int left = l, right = r, mid;
while(left < right)
{
mid = (left + right) / 2;
if(sum[mid] > x)
right = mid;
else
left = mid + 1;
}
return left;
}
int main()
{
scanf("%d%d", &n, &S);
sum[0] = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d", &sum[i]);
sum[i] += sum[i - 1];
}
for(int i = 1; i <= n; i++)
{
int j = upper_bound(i, n + 1, sum[i - 1] + S);
if(sum[j - 1] - sum[i - 1] == S)
{
nearS = S;
break;
}
else if(j <= n && sum[j] - sum[i - 1] < nearS)
{
nearS = sum[j] - sum[i - 1];
}
}
for(int i = 1; i <= n; i++)
{
int j = upper_bound(i, n + 1, sum[i - 1] + nearS);
if(sum[j - 1] - sum[i - 1] == nearS)
printf("%d-%d\n", i, j - 1);
}
return 0;
}