-
Notifications
You must be signed in to change notification settings - Fork 80
/
FAN.py
59 lines (48 loc) · 1.23 KB
/
FAN.py
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
#!/bin/python3
import math
import os
import random
import re
import sys
import collections
def median(v, d):
count = 0
if d%2==0:
m1 = None
m2 = None
for i in range(len(v)):
count += v[i]
if count >= d/2 and m1 is None:
m1 = i
if count >= d/2 + 1:
m2 = i
break
return (m1 + m2)/2
else:
for i in range(len(v)):
count += v[i]
if count > d/2:
return i
return -1
def activityNotifications(expenditure, d):
dq = collections.deque(expenditure[: d])
v = [0]*201
for n in dq:
v[n] += 1
count = 0
for current in expenditure[d:]:
if current >= median(v, d)*2:
count += 1
v[current] += 1
dq.append(current)
v[dq.popleft()] -= 1
return count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nd = input().split()
n = int(nd[0])
d = int(nd[1])
expenditure = list(map(int, input().rstrip().split()))
result = activityNotifications(expenditure, d)
fptr.write(str(result) + '\n')
fptr.close()