#P10455. Minimum Segmentation for CPU Group Testing
Minimum Segmentation for CPU Group Testing
Minimum Segmentation for CPU Group Testing
Advanced CPU Manufacturer (ACM) produces (n) CPUs every day and sells them worldwide. The quality control department tests CPUs in groups as follows:
1. Randomly select (m) pairs (i.e. (2m) CPUs) from the group. If the total number of CPUs is less than (2m), select as many pairs as possible.
2. For each selected pair, compute the Relative Performance Difference (RPD) defined as the absolute difference of their performance values. Let (D_i) be the RPD of the (i^{th}) pair.
3. The Squared Performance Difference (SPD) of the group is (SPD = \sum_i D_i^2).
4. The group passes the quality test if and only if (SPD \le k), where (k) is a given constant.
In practice, ACM tests all (n) CPUs as one group. However, due to the strict standard, some high-performance CPUs fail the test. Xiao S, the head of quality control, has proposed splitting the (n) CPUs into one or more consecutive segments such that each segment passes the group test without modifying the testing process.
For any segment, you can optimally pair the CPUs to minimize the SPD. It can be shown that after sorting the performance values of the segment into (Q_1, Q_2, \dots, Q_L) (where (L) is the segment length), the minimum possible (SPD) is obtained by pairing (Q_{2j-1}) with (Q_{2j}) for (j = 1, 2, \dots, \lfloor L/2 \rfloor); that is, (SPD = \sum_{j=1}^{\lfloor L/2 \rfloor} (Q_{2j} - Q_{2j-1})^2).
Your task is to determine the minimum number of contiguous segments into which the (n) CPUs can be split so that each segment passes the quality test (i.e. its optimal (SPD \le k)).
inputFormat
The first line contains two integers (n) and (k) -- the number of CPUs and the maximum allowed SPD for a segment, respectively.
The second line contains (n) space-separated integers (P_1, P_2, \dots, P_n) representing the performance of each CPU.
outputFormat
Output a single integer: the minimum number of contiguous segments required so that each segment passes the quality test. If it is impossible to split the CPUs satisfying the condition, output -1.
sample
5 1
1 1 1 1 1
1