-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathq2.py
39 lines (34 loc) · 824 Bytes
/
q2.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
#Author: Rik Biswas
def checkDiff(a,b,d):
k = True
for i in range(1,len(b)):
if(b[i]-a[i+1]!=d):
k=False
k=True
k=False
break
return k
def driver(a,b,n):
if (len(a)==2):
if max(a) > b[0]:
return b[0]-min(a)
else:
return b[0]-max(a)
a.sort()
b.sort()
d = b[0]-a[1]
if d <=0:
return b[0]-a[0]
else:
if checkDiff(a,b,d):
return d
else:
return b[0]-a[0]
# print(driver([1,4,3,8],[15,8,11],4))
t = int(input())
for x in range(t):
n = int(input())
a = list(map(int ,input().split(" ")))
b = list(map(int ,input().split(" ")))
print(driver(a,b,n))
print("the changes are done ")