-
Notifications
You must be signed in to change notification settings - Fork 80
/
Fraudulent.java
81 lines (79 loc) · 2.38 KB
/
Fraudulent.java
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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] data = br.readLine().split(" ");
int n = Integer.parseInt(data[0]);
int d = Integer.parseInt(data[1]);
List<Integer> arr = new ArrayList();
Arrays.asList(br.readLine().split(" ")).forEach(val -> arr.add(Integer.parseInt(val)));
int[] hash = new int[201];
int sum,i,ans=0,j,k;
for(i = 0; i<=200; i++){
hash[i] = 0;
}
sum = 0;
for(i=0;i<d;i++){
hash[arr.get(i)]++;
}
for(i=0;i<=200;i++){
sum = sum+hash[i];
if(d%2==1 && sum>d/2){
if(arr.get(d)>=2*i){
ans++;
break;
}
}
else if(d%2==0){
if(sum==d/2){
j=i+1;
while(j<=200 && hash[j]==0)
j++;
if(arr.get(d)>=i+j){
ans++;
break;
}
}
else if(sum>d/2){
if(arr.get(d)>=2*i){
ans++;
break;
}
}
}
}
for(i=d+1;i<n;i++){
hash[arr.get(i-d-1)]--;
hash[arr.get(i-1)]++;
sum = 0;
for(j=0;j<=200;j++){
sum = sum+hash[j];
if(d%2==1 && sum>d/2){
if(arr.get(i)>=2*j){
ans++;
break;
}
}
else if(d%2==0){
if(sum==d/2){
k=j+1;
while(k<=200 && hash[k]==0)
k++;
if(arr.get(i)>=j+k){
ans++;
break;
}
}
else if(sum>d/2){
if(arr.get(i)>=2*j){
ans++;
break;
}
}
}
}
}
System.out.println(ans);
}
}