-
Notifications
You must be signed in to change notification settings - Fork 9
/
CCT B4 - Assigning mice to Holes.py
48 lines (34 loc) · 1.13 KB
/
CCT B4 - Assigning mice to Holes.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
There are N Mice and N holes are placed in a straight line.
Each hole can accomodate only 1 mouse.
A mouse can stay at his position, move one step right from x to x + 1, or move one step left from x to x − 1. Any of these moves consumes 1 minute.
Assign mice to holes so that the time when the last mouse gets inside a hole is minimized.
Input Format
First line contains the integer N. Next line contains N integers, the position of the mice.
Third line contains N integers, the position of the holes.
Constraints
1 <= N <= 105
Output Format
Output one number corresponding to the minimum number of minutes it will take for the last mice to go into the hole.
Sample Input 0
3
4 -4 2
4 0 5
Sample Output 0
4
def assignHole(mices, holes, n, m):
if (n != m):
return -1
mices.sort()
holes.sort()
Max = 0
for i in range(n):
if (Max < abs(mices[i] - holes[i])):
Max = abs(mices[i] - holes[i])
return Max
n=int(input())
mices = list(map(int,input().split()))
holes = list(map(int,input().split()))
n = len(mices)
m = len(holes)
minTime = assignHole(mices, holes, n, m)
print(minTime)