During one day Bessie takes $N$ atmospheric-pressure measurements and numbers them $M_1, M_2, \dots, M_N$ in the order she observes them ($1 \le N \le 100$, $1 \le M_i \le 1{,}000{,}000$).
Bessie wants a subset of the measurements — indices $s_1 < s_2 < \dots < s_K$ ($1 \le K \le N$) — that represents the whole set well, i.e. keeps the error defined below small.
Every index $i$ that is not in the subset contributes an error:
The total error is the sum of these individual errors. Given a maximum error $E$ ($1 \le E \le 1{,}000{,}000$), find the size of the smallest subset whose total error is at most $E$.
For example, with measurements $10, 3, 20, 40$, choosing the 2nd and 4th measurements is optimal and gives a total error of $17$. The measurement before the first chosen index contributes $2 \cdot |10 - 3| = 14$, and the measurement between the two chosen indices contributes $|2 \cdot 20 - (3 + 40)| = 3$.