50000. Alternating Sequence
難度:4/51
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#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
static inline int max(int a, int b){
if(a > b) return a;
else return b;
}
int k, n;
int ans = 0;
int count_pos = 0;
int count_neg = 0;
int now_count = 0;
static inline void update_pos(){
if(count_pos != 0){
if(count_pos > k){
now_count = 1;
}
else if(count_pos == k){
now_count++;
}
else{
now_count = 0;
}
}
ans = max(ans, now_count);
count_pos = 0;
}
static inline void update_neg(){
if(count_neg != 0){
if(count_neg == k){
if(now_count != 0){
now_count++;
}
}
else{
now_count = 0;
}
}
count_neg = 0;
}
int main(){
scanf("%d", &k);
while(scanf("%d", &n) && n != 0){
if(n > 0){ // pos
update_neg();
count_pos++;
}
else{ // neg
update_pos();
count_neg++;
}
}
update_pos();
update_neg();
if(ans == 1) ans = 0;
printf("%d\n", ans * k);
return 0;
}