Doremy’s Connecting Plan Solution
Doremy lives in a country consisting of n cities numbered from 1 to n , with ai people living in the i -th city. It can be modeled as an undirected graph with n nodes.
Doremy resides in a country composed of � cities, numbered from 1 to �, each housing �� people in the �-th city. This country can be represented as an undirected graph with � nodes.
Initially, the graph is devoid of any edges. Doremy’s objective is to create a connected graph. To achieve this, she can connect nodes � and � by adding an edge if the condition ∑�∈���≥�⋅�⋅� is satisfied, where � represents the set of all nodes within the same connected component as either � or �, and � is a given constant.
Can Doremy effectively establish a connected graph?
The input entails multiple test cases. The first line contains a single integer � (1≤�≤104), denoting the number of test cases. The subsequent lines describe each test case.
For each test case: Doremy’s Connecting Plan Solution
- The first line holds two integers: � and � (2≤�≤2×105, 1≤�≤106)—the number of nodes and the constant, respectively.
- The second line of each test case comprises � integers �1,�2,…,�� (0≤��≤1012)—representing the population in each city.
Output is “YES” if it’s possible to make the graph connected, or “NO” otherwise.
For instance, in the first test case, Doremy can establish connections as follows:
- Connect (1,2) as �1+�2=20≥�⋅�⋅�=20.
- Connect (1,3) as �1+�2+�3=35≥�⋅�⋅�=30.
- Connect (1,4) as �1+�2+�3+�4=45≥�⋅�⋅�=40.
The other test cases follow similar conditions and connectivity rules.