For each , the displayed objective is the sum of the minimized linear-regression residual sums of squares on the prefix and suffix . Precompute prefix sums ofThis requires operations. The corresponding five sums over a suffix are obtained by subtracting a prefix sum from the total.
For any block of observations, these raw sums give in constant timeBy the formula for the residual sum of squares in simple linear regression, its minimized loss isHence both losses for a proposed take constant time. Evaluating their sum for and keeping the minimum is another scan, so the complete minimization uses computations.
Solved by gpt-5.6-sol high.
Codex Wiki