-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlerter.java
More file actions
44 lines (36 loc) · 1.37 KB
/
Alerter.java
File metadata and controls
44 lines (36 loc) · 1.37 KB
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
public class Alerter {
public static boolean alert(int[] input, int wSize, double allowedIncrased) {
boolean[] noalert = new boolean[input.length];
double curSum = 0;
for (int i = 0; i < wSize; i++) {
curSum += input[i];
}
int start = 0, end = wSize;
while (end <= input.length) {
for (int i = start; i < end; i++) {
noalert[i] |= input[i] * wSize <= curSum * allowedIncrased;
// System.out.println(i);
// if (i == 4)
// System.out.println("total " + input[i] * wSize + " sum " + curSum * allowedIncrased);
}
// System.out.println(start);
if (!noalert[start]) return true;
if (end == input.length) break;
curSum -= input[start];
curSum += input[end];
start++;
end++;
}
while (start < input.length) {
// System.out.println(start);
// System.out.println(noalert[start]);
if (!noalert[start++]) return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(alert(new int[] {1, 2, 100, 2, 2}, 3, 1.5));
System.out.println(alert(new int[] {1, 2, 4, 2, 2}, 3, 2));
System.out.println(alert(new int[] {1, 2, 100, 2, 2}, 2, 2.5));
}
}