[Solution] Range Assign, Number of Distinct Elements Minimize CodeChef Solution
Problem
You are given an array of positive integers.
In one operation, you can do the following:
- Choose integers and , such that ;
- For all , change the value of to .
Find out whether can have at most distinct values after using any (possibly zero) number of operations.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input:
- The first line of each test case contains - the size of the array.
- The next line contains integers, - the elements of the array.
Output Format
For each test case, print YES
if can have at most distinct values after using any (possibly zero) number of operations and NO
otherwise.
You may print each character of the string in uppercase or lowercase (for example, the strings YES
, yEs
, yes
, and yeS
will all be treated as identical).
Explanation:
Test case : The array already has distinct elements.
Test case : It is impossible to make operations such that has distinct elements.
Test case : We can make an operation as:
- Choose and . Thus, we change to .
The final array is which has two distinct elements.
Test case : We can make an operation as:
- Choose and . Thus, we change and to .
The final array is which has one distinct element.
No comments:
Post a Comment