Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import os
- import random
- import re
- import sys
- import bisect
- # Complete the activityNotifications function below.
- def activityNotifications(expenditure, d):
- temp = []
- temp.extend(expenditure[0:d])
- # Must be initially sorted once
- temp.sort()
- #print(len(temp), len(expenditure[:d]), d, len(expenditure))
- mid, mid1 = None, None
- mid = d // 2
- #print(d, temp, mid, len(temp))
- med = temp[mid]
- if d % 2 == 0:
- mid1 = mid-1
- med += temp[mid]
- med /= 2
- cnt = 0
- for i in range(d, len(expenditure)):
- #print(temp, d, expenditure[i])
- if expenditure[i] >= 2*med:
- cnt += 1
- idx = bisect.bisect(temp, expenditure[i-d])
- #print(idx)
- del temp[idx]
- bisect.insort(temp, expenditure[i])
- med = temp[mid]
- if mid1 != None:
- med += temp[mid1]
- med /= 2
- return cnt
- if __name__ == '__main__':
- nd = input().split()
- n = int(nd[0])
- d = int(nd[1])
- expenditure = list(map(int, input().rstrip().split()))
- result = activityNotifications(expenditure, d)
- print(str(result) + 'n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement