Catch the Thief Codechef Solution

Hello Programmers In this post, you will know how to solve the Catch the Thief Codechef Solution.

Catch the Thief Codechef Solution
Catch the Thief Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.


A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between 00 and NN (inclusive).

Initially, the policeman is at a coordinate xx and the thief is at a coordinate yy. During each second, each of them must move to the left or right (not necessarily both in the same direction) by distance exactlyexactly equal to KK. No one may go to the left of the coordinate 00 or to the right of NN. Both the policeman and the thief move simultaneously and they cannot meet while moving, only at the end of each second.

Will the policeman be able to catch the thief if they both move optimally? The thief is caught as soon as the policeman and thief meet at the same position at the same time.


  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains four space-separated integers xx, yy, KK and NN.


For each test case, print a single line containing the string "Yes" if the thief can be caught or "No" if the thief cannot be caught (without quotes).


  • 1≤T≤1,0001≤T≤1,000
  • 1≤N≤1091≤N≤109
  • 1≤K≤N1≤K≤N
  • 0≤x,y≤N0≤x,y≤N
  • x≠yx≠y

Sample Input 1 

0 1 1 1
1 4 1 5
4 2 1 7
3 7 2 10
8 2 3 15

Sample Output 1 



Example case 1: The policeman is at 00 and the thief is at 11. After the 11-st second, the policeman is at 11 and the thief is at 00. After the next second, the policeman is again at 00 and the thief at 11. They cannot end up at the same coordinate

Catch the Thief CodeChef Solution in JAVA

import java.util.*;
public class Main {
	public static void main(String[] args) {
   Scanner sc=new Scanner(;
	int t=sc.nextInt();
      long x=sc.nextLong();
      long y=sc.nextLong();
      long k=sc.nextLong();
      long n=sc.nextLong();
	}catch(Exception e){return;}

Catch the Thief CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main()
    int t;
    cin >> t;
    while (t--)
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int k = b - a;
        if (k < 0)
            k = k * -1;
        if ((k)%(2*c)==0)
            cout << "Yes\n";
            cout << "No\n";
    return 0;

Catch the Thief CodeChef Solution in Python

for _t in range(t):
    n,m,o,p=map(int,input().split(" "))

Disclaimer: The above Problem (Catch the Thief ) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Hard Cash Codechef Solution

Leave a Reply

Your email address will not be published. Required fields are marked *