A function $f$ accepts two equally-long arrays $A$ and $B$ as input, and returns a real number $s$ such that the root mean square of $A-sB$ is minimal.
I'm hoping to come up with a better-than-brute-force approach to the following problem:
Given a pair of equally-long ($n \sim 10^7$) arrays $C,D$ of numbers from the interval $[-1,1]\subset\mathbb{R}$, how are array indices $i,j$ chosen that satisfy
a) $j-i \gtrsim 10^4$
b) $s=f\left(C[i\dots j],D[i\dots j]\right)$ is 'optimal', in the sense that if indices $k,l$ satisfy $k\leq i<j\leq l$, then
$$\text{RMS}(C[i\dots j]-sD[i\dots j]) \leq \text{RMS}(C[i\dots j]-s'D[i\dots j])$$
where $s'=f\left(C[k\dots l],D[k\dots l]\right)$.
(I'm hoping that by recursing on the subarrays to the left and right of these 'optimal' subarrays, the entirety of the pair of large arrays can be processed... 'optimally'.)
I'll be grateful for even a piece of jargon describing the abstract approach this is surely an instance of. Apologies for notational abuses and not-entirely-appropriate title - hope the point is clear.