-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapartments.py
More file actions
71 lines (57 loc) · 1.3 KB
/
apartments.py
File metadata and controls
71 lines (57 loc) · 1.3 KB
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
# =======================
# Python CP Template
# (bits/stdc++.h equivalent)
# =======================
import sys
import math
import threading
# Fast I/O
input = sys.stdin.readline
def print(x):
sys.stdout.write(x)
sys.stdout.flush()
# Common imports
from collections import defaultdict, deque, Counter
from itertools import combinations, permutations, product, accumulate
from functools import lru_cache, reduce
import heapq
import bisect
# Constants
INF = float('inf')
MOD = 10**9 + 7
# =======================
# Utility Functions
# =======================
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
# =======================
# Main Logic
# =======================
def solve():
arr = list(map(int, input().split()))
n,m,k = arr[0],arr[1],arr[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
ans = 0
i,j = 0,0
while i < n and j < m:
if A[i] > B[j]+k:
j+=1
elif B[j]-k > A[i]:
i+=1
elif B[j]-k <= A[i] and A[i] <= B[j]+k:
ans+=1
i+=1
j+=1
sys.stdout.write(str(ans)+"\n")
# =======================
# Entry Point
# =======================
if __name__ == "__main__":
solve()