0

Can anyone optimize this code.

for _ in range(int(input())): p,t = map(int,input().split()) i=0 if(p==t): print(0) elif(p>t): while(p>t): i+=1 p-=2 t-=1 print(i) elif(p<t): while(p<t): i+=1 p+=2 t+=1 print(i) Input 3 1 3 2 1 1 1 Output 2 1 0

20th Apr 2022, 5:21 PM
Akash Gupta
Akash Gupta - avatar
9 Respuestas
+ 4
Just put 1st two lines plus print(abs(p-t) )
20th Apr 2022, 6:55 PM
Jayakrishna 🇮🇳
+ 2
Can you please summarize what the code is supposed to do? Print the absolute difference of a pair of numbers?
20th Apr 2022, 6:47 PM
Lisa
Lisa - avatar
0
Lisa it's a codeshef problem in which there's is a policeman and a theif they running on a same direction but policeman can run 2 steps in 1 sec and theif can run 1 step in 1 second .so we want to tell how much policeman take to catch the theif. As you see first input 1 3 here in 1 position policeman are there and in 3 position theif are then we want to tell in how much second policeman will catch the theif. Or you can search on google if you want full question Police and theif codeshef problem.
22nd Apr 2022, 7:19 AM
Akash Gupta
Akash Gupta - avatar
0
Jayakrishna🇮🇳 you can also search on google for better understanding of question
22nd Apr 2022, 7:20 AM
Akash Gupta
Akash Gupta - avatar
0
If you need help, it is actually *your* job to explain what you are trying to do – and not ours to guess and google it 😉
22nd Apr 2022, 7:23 AM
Lisa
Lisa - avatar
23rd Apr 2022, 11:08 AM
Jayakrishna 🇮🇳
0
Lisa okay but i tried my best to explain . thank you giving your time.
23rd Apr 2022, 4:31 PM
Akash Gupta
Akash Gupta - avatar
0
Akash Gupta Your summary is fine, I just wanted to point out that the task description is important so we know.what the code is about :)
23rd Apr 2022, 4:33 PM
Lisa
Lisa - avatar
0
Akash Gupta why I need to search? Between are you asking about this question? In DM.. Is it not solved?
23rd Apr 2022, 4:49 PM
Jayakrishna 🇮🇳