-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanothermaximumaddition.cpp
More file actions
45 lines (43 loc) · 880 Bytes
/
Copy pathanothermaximumaddition.cpp
File metadata and controls
45 lines (43 loc) · 880 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
#include <stdio.h>
#define ll long long
int main()
{
int tc;
scanf("%d", &tc);
for (int i = 0; i < tc; i++)
{
ll n, m;
ll flag = 0;
ll count = 0;
ll length = 0;
scanf("%lld %lld", &n, &m);
ll a[10005];
for (int ii = 0; ii < n; ii++)
{
scanf("%lld", &a[ii]);
}
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;
}