-
Notifications
You must be signed in to change notification settings - Fork 1
/
FraudActivity.cpp
84 lines (65 loc) · 1.19 KB
/
FraudActivity.cpp
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
82
83
84
// problem: "https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem"
#include<iostream>
#include<vector>
using namespace std;
int median(vector<int>&C,int d)
{
int i,s=0;
int dcopy = d;
if(d%2)
d = (d+1)/2;
else
d = d/2;
i = 0;
while(s<d)
{
if(s+C[i]<d)
s += C[i];
else if(s+C[i]==d)
{
if(dcopy%2)
{
return 2*i;
}
int j = i+1;
while(C[j]==0)
j++;
return (i+j);
}
else
{ // s<d && s+C[i]>d
return 2*i;
}
i++;
}
return i;
}
int main()
{
vector<int>C(201,0);
int d,n,i,s,x,y;
cin>>n>>d;
vector<int>S;
s = 0;
for(i=0;i!=n;i++)
{
if(i<d)
{
cin>>x;
C[x]++;
S.push_back(x);
}
else
{
cin>>x;
S.push_back(x);
if(i-d-1>=0)
C[S[i-d-1]]--;
if(x>=median(C,d)) // define function
s++;
C[x]++;
}
}
cout<<s;
return 0;
}