adplus-dvertising

Group Assignment CodeChef Solution

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 yES, YeS, YES and yes mean the same.

Constraints

  • 1‚ȧT‚ȧ10001‚ȧT‚ȧ1000
  • 2‚ȧN‚ȧ1052‚ȧN‚ȧ105
  • 2‚ȧPi‚ȧN2‚ȧ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¬†22,¬†44¬†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.