forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalien.cpp
More file actions
27 lines (27 loc) · 682 Bytes
/
alien.cpp
File metadata and controls
27 lines (27 loc) · 682 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
// 2014-09-23
#include <cstdio>
int main() {
int T; scanf("%d", &T);
int p[100000];
while (T--) {
int A, B;
scanf("%d %d", &A, &B);
for (int i = 0; i < A; i++) {
scanf("%d", p+i);
}
int l = 0, r = 0, sum = 0;
int bests = -1, bestp;
for (;;) {
if (sum <= B) {
if (r - l > bests || r - l == bests && sum < bestp) {
bests = r -l; bestp = sum;
}
if (r == A) break;
else sum += p[r++];
} else {
sum -= p[l++];
}
}
printf("%d %d\n", bestp, bests);
}
}