forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotels.c
81 lines (81 loc) · 1.97 KB
/
hotels.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
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
/* 2014-04-30 */
#include <stdio.h>
int get() {
int res = 0;
int c;
do {
c = getchar_unlocked();
} while (c <= 32);
do {
res = 10*res + c - '0';
c = getchar_unlocked();
} while (c > 32);
return res;
}
int a[300000];
int main() {
int N = get(), M = get();
int best = 0, l = 0, sum = 0, i = 0;
int n = (N + 7) / 8;
switch (N % 8) {
case 0: do {
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 7:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 6:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 5:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 4:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 3:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 2:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
case 1:
sum += a[i] = get();
while (sum > M || sum < 0) {
sum -= a[l++];
}
if (sum > best) best = sum;
i++;
} while (--n > 0);
}
printf("%d\n", best);
return 0;
}