-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALIEN.cpp
86 lines (69 loc) · 1.59 KB
/
ALIEN.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
LITTLE BIT OF MODIFICATION IN SLIDING WINDOW ALGORITHM
*/
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#define get getchar_unlocked
inline int input()
{
int n = 0, s = 1 ;
char p = get();
if (p == '-') {
s = -1 ;
}
while ((p < '0' || p > '9') && p != EOF && p != '-') {
p = get( ) ;
}
if (p == '-') {
s = -1, p = get() ;
}
while (p >= '0' && p <= '9') {
n = (n << 3) + (n << 1) + (p - '0') ;
p = get() ;
}
return n * s ;
}
using namespace std;
long int arr[300005];
int main()
{
int t;
//scanf("%d", &t);
t = input();
while (t--) {
long int n, totalpeople, maxpeople = 0, x = 0, i, currentbstnumberofstation = 0, currentmaxpeople = 10000005;
//scanf("%ld%ld", &n, &totalpeople);
n = input();
totalpeople = input();
for (i = 0;i < n;i++) {
arr[i] = input();
//scanf("%ld", &arr[i]);
}
for (i = 0;i < n;) {
if (maxpeople <= totalpeople) {
maxpeople += arr[i];
i++;
}
if (maxpeople > totalpeople) {
while (maxpeople > totalpeople) {
maxpeople -= arr[x];
x++;
}
}
if (fabs(x - i) > currentbstnumberofstation) {
currentmaxpeople = maxpeople;
currentbstnumberofstation = fabs(x - i);
} else if (fabs(x - i) == currentbstnumberofstation) {
if (maxpeople < currentmaxpeople) {
currentmaxpeople = maxpeople;
currentbstnumberofstation = fabs(x - i);
}
}
//printf("%ld %ld\n", i, x);
}
printf("%ld %ld\n", currentmaxpeople, currentbstnumberofstation);
}
return 0;
}