The One with Russ solution codechef

The One with Russ solution codechef

Rachel has a date and tells everyone she is not mad at Ross but doesn’t have any feelings for him anymore either. Seeing her date for the first time, everyone notices that he looks exactly like Ross. However, Rachel refuses to believe so.

Rachel makes a list of NN characteristics and assigns a score to both Ross and Russ for each of the characteristics. Ross’ ithith characteristic has a score equal to AiAi and Russ’ ithith characteristic has a score equal to BiBi. Rachel decides that Russ looks exactly like Ross if the following condition is satisfied for at least XX distinct values of jj1jN1≤j≤N :

  • |AjBj|K|Aj−Bj|≤K.

Help Rachel in finding if both are alike.

The One with Russ solution codechef Input Format

  • First line will contain TT, number of testcases. Then the testcases follow.
  • First line for each test case contains three integers NNXX and KK, denoting the number of characteristics, the minimum number of characteristics and maximum possible score difference.
  • Second line for each test case contains NN integers denoting array AA.
  • Third line for each test case contains NN integers denoting array BB.

Output Format

For each test case print “YES” if they are alike, else print “NO”.

You may print each character of each string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints The One with Russ solution codechef

  • 1T101≤T≤10
  • 1N1031≤N≤103
  • 1Ai,Bi1031≤Ai,Bi≤103
  • 1Xn1≤X≤n
  • 0K1030≤K≤103

Sample Input 1 

3
4 2 2
1 7 7 5
1 8 1 2
5 1 3
9 8 7 2 5
5 4 1 8 9
3 3 0
2 3 4
2 3 4

The One with Russ solution codechef Sample Output 1 

YES
NO
YES

Explanation

Test case 1: The values of absolute difference between scores of Ross’ and Russ’ characteristics 11 and 22 are 00 and 11 respectively, both these values are less than K=2K=2. Thus, Ross and Russ are alike.

Test case 2: The values of absolute difference between the scores of ALL of the Ross’ and Russ’ characteristics are greater than 33.

Leave a Comment

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