#B3820. Energy Reactions in Tivat
Energy Reactions in Tivat
Energy Reactions in Tivat
In the world of Tivat, there exist \(n\) elements. Each element \(i\) holds an energy \(a_i\). When two different elements \(i\) and \(j\) react under specific conditions, all elements have their energies doubled.
Reaction Conditions: For any two different elements \(i\) and \(j\) (with \(i \neq j\)), a reaction can occur if either:
- \(a_i \times a_j\) is a multiple of \(154 = 2 \times 7 \times 11\), or
- \(a_i \times a_j\) is a multiple of \(147 = 3 \times 7^2\).
Reaction Result: When a reaction occurs between any two elements meeting the condition, the energy of every element (i.e. each \(a_i\)) is doubled.
Reaction Frequency: There is no limit on the number of reactions. In fact, if a valid reaction exists, it can be repeated indefinitely, causing the sheer sum of energies to eventually exceed any given threshold.
The task is to determine whether by performing a series of reactions (possibly zero) you can achieve a total energy sum \(S = a_1 + a_2 + \cdots + a_n\) that is at least \(k\).
Hint: If the initial sum \(S\) is already \(\geq k\), you should output YES
. Otherwise, if there exists at least one valid pair \((i,j)\) for which the reaction condition holds, you can perform sufficient reactions to eventually raise the sum above \(k\) (since every reaction doubles the sum). If neither condition holds then output NO
.
inputFormat
The first line contains two integers \(n\) and \(k\) separated by a space.
The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the energies of the elements.
outputFormat
Output a single line containing YES
if it is possible to achieve a total energy sum \(S \geq k\) after performing zero or more reactions. Otherwise, output NO
.
sample
2 100
2 77
YES