#P11886. Merging Numbers for Maximum Score
Merging Numbers for Maximum Score
Merging Numbers for Maximum Score
Given positive integers \(n\) and \(m\) and an integer sequence \(a_1,a_2,\dots,a_n\). In each move, you may choose two numbers \(x\) and \(y\), remove them from the sequence and insert \(x+y\). You earn one point if the following conditions hold:
\(m\cdot x \ge y\) and \(m\cdot y \ge x\).
The task is to merge all the numbers into a single number while maximizing the total score (the number of merge operations in which the conditions are satisfied). Note that a merge operation is always allowed, but you only obtain a point if the two numbers being merged satisfy the condition \(\max(x,y) \le m\cdot \min(x,y)\). The final merge (when only one number remains) is counted in the score if the condition holds at that step.
inputFormat
The input begins with a line containing two integers \(n\) and \(m\) (the number of numbers and the parameter, respectively).
The next line contains \(n\) positive integers \(a_1, a_2, \dots, a_n\), representing the sequence.
outputFormat
Output a single integer: the maximum possible score (the number of valid merge operations) achievable when merging all numbers into one.
sample
3 2
1 3 4
1