[Solution] Average Gift solution codechef

Average Gift solution codechef – Chef has a set SS containing NN distinct integers.

Chef wants to gift Chefina an array AA of any finite length such that the following conditions hold true:

  • AiSAi∈S i∀i. In other words, each element of the array AA should belong to the set SS.
  • Mean value of all the elements in AA is exactly XX.

[Solution] Average Gift solution codechef

Find whether there exists an array AA of finite length satisfying the above conditions.

Input Format

  • First line will contain TT, the number of test cases. Then the test cases follow.
  • First line of each test case contains two integers NN and XX – denoting the size of set SS and the mean value of the required array.
  • Second line contains NN distinct integers S1,S2,,SNS1,S2,…,SN – denoting the set SS.

Output Format

For each test case, output in a single line, YES if there exists an array satisfying the given conditions, NO otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings YESyEsyes, and yeS will all be treated as identical).

[Solution] Average Gift solution codechef

  • 1T10001≤T≤1000
  • 1N1051≤N≤105
  • 1Si1091≤Si≤109
  • 1X1091≤X≤109
  • SiSjSi≠Sj for iji≠j
  • Sum of NN over all test case do not exceed 21052⋅105.

Sample Input 1 

3 2
1 2 3
1 5
2 5
4 6
1 5

Sample Output 1 


[Solution] Average Gift solution codechef Explanation

Test Case 11: One of the valid arrays is A=[2,2]A=[2,2]. Here, 2{1,2,3}2∈{1,2,3}. Also, mean value of the array is 2+22=22+22=2.

Test Case 22: Since all elements of the array can only be equal to 33, the mean value of AA cannot be equal to 55.

Test Case 33: One of the valid arrays is A=[4,6]A=[4,6]. Here, 4{4,6}4∈{4,6} and 6{4,6}6∈{4,6}. Also, mean value of the array is 4+62=54+62=5.

Test Case 44: One of the valid arrays is A=[5]A=[5]. Here, 5{5}5∈{5}. Also, mean value of the array is 51=551=5.

For Solution

Click here

Leave a Comment