-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.c
41 lines (40 loc) · 877 Bytes
/
D.c
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
#include <stdio.h>
int main()
{
long long tc;
scanf("%lld", &tc);
for (int i = 0; i < tc; i++)
{
long long n, m;
long long flag = 0;
long long count = 0;
long long length = 0;
scanf("%lld %lld", &n, &m);
long long a[10005];
for (int j = 0; j < n; j++)
{
scanf("%lld", &a[j]);
}
for (int j = 0; j < n; j++)
{
flag += a[j];
count++;
while (flag > m)
{
flag -= a[j - count + 1];
count--;
}
if (count > length)
{
length = count;
}
}
if (length > 0)
{
printf("Case #%d: %lld\n", i + 1, length);
}
else
printf("Case #%d: -1\n", i + 1);
}
return 0;
}