Solution (source code)

= Solution

The <coefficient> sum is finite, so the <Weierstrass M-test> makes the cosine series uniformly convergent and $f$ continuous. Put $Q=5^{m+1}$ and $A_m=\sum_{k=m+1}^{\infty}a_k$. The indicated partial sum belongs to $\mathcal T_n$ because its largest frequency is $5^m\le n$. Its tail satisfies
$$
|f(x)-t_n(x)|\le A_m,
$$
and equality holds at $x=0$. Thus its <supremum norm> error is exactly $A_m$.

At the $2Q$ points $x_j=j\pi/Q$, $0\le j<2Q$, every omitted frequency is an odd <integer> multiple of $Q$. Indeed for $k\ge m+1$,
$$
\cos(5^kx_j)=\cos(5^{k-m-1}j\pi)=(-1)^j.
$$
<Uniform convergence> permits summing these values, giving
$$
f(x_j)-t_n(x_j)=(-1)^j A_m.
$$
These are cyclically alternating extrema. Since $n<Q$, there are $2Q\ge2n+2$ of them, so the <trigonometric Chebyshev alternation theorem> proves that the partial sum is the unique best approximant. Consequently the <positive lacunary trigonometric series> has
$$
\boxed{t_n(x)=\sum_{k=0}^ma_k\cos(5^kx),\qquad
E_n(f)=\sum_{k=m+1}^{\infty}a_k\quad(5^m\le n<5^{m+1}).}
$$
The positivity of every tail <coefficient> makes the same tail attain its full <coefficient> sum with alternating signs; a triangle bound alone would not establish optimality.