-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalien.cpp
35 lines (35 loc) · 973 Bytes
/
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
#include<cstdio>
int main() {
int test;
scanf("%d", &test);
while(test--) {
int a, b;
scanf("%d %d", &a, &b);
int *stations = new int[a];
for(int i=0;i<a;++i) {
scanf("%d", stations + i);
}
int startPtr = 0;
int endPtr = 0;
int curSum = stations[0];
int maxLen = 0;
int maxFolks = 0;
while(endPtr < a) {
if(curSum > b) {
curSum -= stations[startPtr];
startPtr++;
} else {
int delta = endPtr - startPtr + 1;
if(maxLen == delta && curSum < maxFolks) {
maxFolks = curSum;
} else if(maxLen < delta) {
maxLen = delta;
maxFolks = curSum;
}
endPtr++;
curSum += stations[endPtr];
}
}
printf("%d %d\n", maxFolks, maxLen);
}
}