Making friends

1.8

25 votes
Graphs, Algorithms, Graph Representation
Problem

You opened a school with N students. Each student will either belong to Team Red or Team Blue. The students in each team are friends with each other. However, you want them to make friends with students from the opposite team too. For example, if a student belongs to Team Red, you want that student to make friends with students from Team Blue.

Note: Friendship is mutual. If A is B's friend, then B is automatically A's friend. 

You give each student a number M that represents the number of friends that the student should have from the opposite team.

Your task is to determine whether it is possible for each student to have the number of friends represented by the number M.

Input format

  • The first line of input is a number T denoting the number of test cases.
  • In each test case:
    • The first line contains a positive integer N denoting the number of students.
    • The second line contains an integer M denoting the number of friends that the student should have from the opposite team.

Output format

Print "Yes" or "No" in a new line for each test case based on the possibility that a student can have the number of friends represented by the number M.

Constraints

1<= T <=2*10^5

1 <= N <= 10^5
0 <= M <= 10^5

 

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For example n=2, m=1
There are 2 students in the school, student 1 belonging to Team Red and student 2 belonging to Team Blue, if they become friends then their requirements will be fullfilled as they both require a friend, each. 

Editor Image

?