-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem-4.py
71 lines (68 loc) · 1.78 KB
/
Problem-4.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
t=int(input())
ans=[]
for i in range(t):
n=int(input())
w=input()
w=list(map(int, w.split()))
l=input()
l=list(map(int, l.split()))
if (n==2):
if (w[0]>w[1]):
if (l[0]==1):
ans.append(2)
else:
ans.append(1)
else:
ans.append(0)
elif(n==3):
d={}
length={}
jumps=0
for z in range(3):
if (w[z]==1):
d[1]=z
length[1]=l[z]
elif(w[z]==2):
d[2]=z
length[2]=l[z]
elif(w[z]==3):
d[3]=z
length[3]=l[z]
while((d[1]>=d[2]) or (d[2]>=d[3])):
while (d[1]>=d[2]):
d[2]+=length[2]
jumps+=1
while(d[2]>=d[3]):
d[3]+=length[3]
jumps+=1
ans.append(jumps)
elif(n==4):
d={}
length={}
jumps=0
for z in range(4):
if (w[z]==1):
d[1]=z
length[1]=l[z]
elif(w[z]==2):
d[2]=z
length[2]=l[z]
elif(w[z]==3):
d[3]=z
length[3]=l[z]
elif(w[z]==4):
d[4]=z
length[4]=l[z]
while((d[1]>=d[2]) or (d[2]>=d[3]) or (d[3]>d[4])):
while (d[1]>=d[2]):
d[2]+=length[2]
jumps+=1
while(d[2]>=d[3]):
d[3]+=length[3]
jumps+=1
while(d[3]>=d[4]):
d[4]+=length[4]
jumps+=1
ans.append(jumps)
for i in ans:
print(i)