Remark: As pointed out by @leslie townes, this is the so-called the Kantorovich inequality. Years ago, I came up with a proof myself (However, perhaps it is not new).
Problem: Let $a_k \ge 0$, $k = 1, 2, \cdots, n$ with $\sum_{k=1}^n a_k = 1$.
Let $0 < \lambda_1 \le \lambda_2 \le \cdots \le \lambda_n$. Prove that
$$\Big(\sum_{k=1}^n \lambda_k a_k\Big)
\Big(\sum_{k=1}^n \frac{a_k}{\lambda_k}\Big)\le \frac{(\lambda_1+\lambda_n)^2}{4\lambda_1\lambda_n}.$$
Proof:
If $\lambda_1 = \lambda_n$, the inequality is clearly true.
In the following, assume $\lambda_1 < \lambda_n$.
Consider the optimization problem
$$\max_{a_k\ge 0, \forall k; \ \sum_{k=1}^n a_k = 1} \Big(\sum_{k=1}^n \lambda_k a_k\Big)
\Big(\sum_{k=1}^n \frac{a_k}{\lambda_k}\Big).$$
Let $(a_1^\ast, a_2^\ast, \cdots, a_n^\ast)$ be a global maximizer.
We claim that if $\lambda_1 < \lambda_k < \lambda_n$, then $a_k^\ast = 0$.
Indeed, if $a_k^\ast > 0$, let
$$a_1' = a_1^\ast + (1 - y) a_k^\ast, \quad a_k' = 0, \quad a_n' = a_n^\ast + y a_k^\ast$$
where $\frac{\lambda_k - \lambda_1}{\lambda_n - \lambda_1} < y <
\frac{\lambda_n}{\lambda_k}\cdot \frac{\lambda_k - \lambda_1}{\lambda_n - \lambda_1}$. We have
$$a_1' + a_k' + a_n' = a_1^\ast + a_k^\ast + a_n^\ast,$$
and
\begin{align}
\lambda_1 a_1' + \lambda_k a_k' + \lambda_n a_n' &= \lambda_1 a_1^\ast + \lambda_n a_n^\ast
+ [\lambda_1 + (\lambda_n - \lambda_1) y]a_k^\ast \\
&> \lambda_1 a_1^\ast + \lambda_n a_n^\ast
+ \left(\lambda_1 + (\lambda_n - \lambda_1)\cdot \frac{\lambda_k - \lambda_1}{\lambda_n - \lambda_1}\right)a_k^\ast\\
&= \lambda_1 a_1^\ast + \lambda_n a_n^\ast + \lambda_k a_k^\ast,
\end{align}
and
\begin{align}
\frac{a_1'}{\lambda_1} + \frac{a_k'}{\lambda_k} + \frac{a_n'}{\lambda_n}
&= \frac{a_1^\ast}{\lambda_1} + \frac{a_n^\ast}{\lambda_n}
+ \left(\frac{1}{\lambda_1} - \frac{\lambda_n - \lambda_1}{\lambda_1 \lambda_n}y\right)a_k^\ast \\
&> \frac{a_1^\ast}{\lambda_1} + \frac{a_n^\ast}{\lambda_n}
+ \left(\frac{1}{\lambda_1} - \frac{\lambda_n - \lambda_1}{\lambda_1 \lambda_n}
\cdot \frac{\lambda_n}{\lambda_k}\cdot \frac{\lambda_k - \lambda_1}{\lambda_n - \lambda_1}\right)a_k^\ast \\
&= \frac{a_1^\ast}{\lambda_1} + \frac{a_n^\ast}{\lambda_n}
+ \frac{a_k^\ast}{\lambda_k}.
\end{align}
However, this contradicts the optimality of $(a_1^\ast, a_2^\ast, \cdots, a_n^\ast)$.
Now, assume that, among $\lambda_1, \lambda_2, \cdots, \lambda_n$, there are $p$ elements
equal to $\lambda_1$, and there are $q$ elements equal to $\lambda_n$, where $p + q \le n$.
Denote $A = a_1^\ast + a_2^\ast + \cdots + a_p^\ast$ and $B = a_{n-q+1}^\ast + a_{n-q+2}^\ast + \cdots + a_n^\ast$.
We have $A + B \le 1$. We have
\begin{align}
&\Big(\sum_{k=1}^n \lambda_k a_k^\ast\Big)
\Big(\sum_{k=1}^n \frac{a_k^\ast}{\lambda_k}\Big)\\
=\ & \Big(\lambda_1 A + \lambda_n B\Big)\left(\frac{A}{\lambda_1} + \frac{B}{\lambda_n}\right)\\
=\ & (A + B)^2 + \left(\frac{\lambda_1}{\lambda_n} + \frac{\lambda_n}{\lambda_1} - 2\right)AB\\
\le\ & 1 + \left(\frac{\lambda_1}{\lambda_n} + \frac{\lambda_n}{\lambda_1} - 2\right)\cdot \frac{1}{4}\\
=\ & \frac{(\lambda_1+\lambda_n)^2}{4\lambda_1\lambda_n}.
\end{align}
We are done.