This is an extremely (perhaps embarrassingly) basic question.
Suppose I want to choose a distribution $\varphi(x)$ in order to maximize the following expression $K(\mathbb{E}[1-X])$ for some constant $K$. I can set up the following maximization objective.
\begin{equation}J[\varphi] = K\int_{0}^{\infty}(1-x)\varphi(x)dx - \lambda \bigg[ \int_{0}^{\infty}\varphi(x)dx - 1\bigg]\end{equation}
To find local extrema, I take the functional derivative and set equal to $0$; hence
$$\tag{$1$}\label{1}K(1-x) - \lambda = 0$$
However, since the expectation operator is linear, I should be able to solve the equivalent problem, that of maximizing $-K\mathbb{E}[X]$. I want to maximize
\begin{equation}J[\varphi] = -K\int_{0}^{\infty}x\varphi(x)dx - \lambda \bigg[ \int_{0}^{\infty}\varphi(x)dx - 1\bigg]\end{equation}
As above, I take the functional derivative and set equal to $0$, which yields
$$\tag{$2$}-Kx - \lambda = 0$$
which is not the same as in (\ref{1}), but it should be! What am I doing wrong?