We Are Discuss About CODECHEF SOLUTION

Group Assignment CodeChef Solution

Group Assignment CodeChef Solution

Chef is hosting a party at his house and NN people are invited to it. Everyone has arrived and they are eager to make a group and chit-chat.

The ithith person prefers to be in a group of exactly PiPi people (including himself). A person who is not in a group of preferred size gets upset. Find whether Chef would be able to assign every person to a group such that everyone remains happy.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains an integer NN — the number of people at the party.
    • The next line contains the array PP — where PiPi denotes the preferred group size for ithith person.

Group Assignment CodeChef Solution

Output Format

For each test case, output YES, if Chef can assign every person to a group such that everyone remains happy. Otherwise output NO.

The output is case-insensitive, meaning that outputs such as yESYeSYES and yes mean the same.

Constraints

  • 1T10001≤T≤1000
  • 2N1052≤N≤105
  • 2PiN2≤Pi≤N
  • Sum of NN over all test cases does not exceed 105105.

Sample Input 1 

4
5
2 3 2 3 3
5
5 5 5 5 5
5
3 2 2 3 2
4
4 4 4 3

Sample Output 1 

YES
YES
NO
NO

Explanation

Group Assignment CodeChef Solution

Test case 11:

  • Person 11 and 33 can make a group (As both want to be in a group of 22).
  • Person 2244 and 55 can make a group (As they all want to be in a group of 33).

So, there is a possible arrangement that Chef can make so that all of them are happy.

Test case 22:

  • All of the 55 people can make a group (As all want to be in a group of 55).

So, there is a possible arrangement that Chef can make so that all of them are happy.

Test case 33: It can be shown that there is no possible arrangement that Chef can make so that all of them are happy.

Test case 44: It can be shown that there is no possible arrangement that Chef can make so that all of them are happy.

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE

Related Posts

One thought on “Group Assignment CodeChef Solution

Leave a Reply

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