-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcod1.py
More file actions
44 lines (40 loc) · 944 Bytes
/
cod1.py
File metadata and controls
44 lines (40 loc) · 944 Bytes
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
# cook your dish here
def mergeSort(alist):
if len(alist)>1:
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i=0
j=0
k=0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1
while i < len(lefthalf):
alist[k]=lefthalf[i]
i=i+1
k=k+1
while j < len(righthalf):
alist[k]=righthalf[j]
j=j+1
k=k+1
n,k=map(int,input().split())
a=[0]*n
a=list(map(int,input().split()))
a=mergeSort(a)
s=0
for i in range(n-1):
if(a[n-1]-a[i]<k):
break
for j in range(i+1,n):
if(a[j]-a[i]>=k):
s+=n-j
break
print(s)