Optimization of Functional I am looking to maximize a functional for $q(\theta)$ of the following form: $$ \max_{q(\cdot)} \int p(\theta) q (\theta) - \max\{\theta a, (1-\theta)b \} \; \mathrm{d} \theta$$ subject to $$ \int q(\theta) \; \mathrm{d} \theta = c$$ where $p(\theta) \in \mathbb{R}_+$, $\theta \in [0,1]$, $q(\theta) \in [a,b]$, $a,b,c \in \mathbb{R}_+$, and boundary conditions are such that $q(0) = a$, $q(1)=b$. 
I am very new to functional analysis and am unfamiliar with how I might approach a problem like this. Any resources would be appreciated. I first thought of using Euler-Lagrange, but the linearity of the objective in $q$ means no information comes out about the optimal $q(\theta)$. As far as the constraint goes, I've had some experience with Lagrange maximization, but only functions and not functionals. 
Lastly, I'm wondering how this would extend to arbitrary $n$ dimensions for
$q(\boldsymbol{\theta})$:  $$\max_{\boldsymbol{q}(\boldsymbol{\cdot})} \int_D \boldsymbol{p}(\boldsymbol{\theta}) \boldsymbol{q}(\boldsymbol{\theta}) - \max\{\theta_1b_1,\cdots, \theta_n b_n\} \; \mathrm{d} \boldsymbol{\theta} $$ subject to $$ \int q_1(\theta_1) \; \mathrm{d} \theta_1 = c_1$$ $$ \vdots $$  $$ \int q_n(\theta_n) \; \mathrm{d} \theta_n = c_n$$ where $\boldsymbol{\theta} \in \mathbb{R}^n$, and $\boldsymbol{p}, \boldsymbol{q}: \mathbb{R}^n \to \mathbb{R}^n$, and the constraints are 1-dimensional component-wise.  Here, $D=\times_{i=1}^n [0,1]$, and like before, $\boldsymbol{q}(\boldsymbol{\theta}) \in [a_1,b_1] \times \cdots \times [a_n,b_n]$, with $a_i,b_i,c_i \in \mathbb{R}_+$ for all $i$. Lastly, boundary conditions are such that $\boldsymbol{q}((x_1,\cdots, 0_j, \cdots, x_n)) = (y_1, \cdots, 0_j, \cdots, y_n)$. Essentially, the image of $\boldsymbol{q}$ takes on the corner values when evaluated at the vertices of its compact support. 
Any help or resource would be greatly appreciated. Thanks again. 
 A: This is not really a typical variational problem, but more a disguised
linear programming problem. 
Note that the term $- \max\{\theta a, (1-\theta)b \}$ in the functional
does not depend on $q$, so for the purpose of finding maximizers, we can
simply ignore it. We are then left with the problem of maximizing 
$\int p(\theta) q (\theta)  \; \mathrm{d} \theta$ subject to the constraints
$a \le q(\theta) \le b$ and $\int q(\theta) \; \mathrm{d} \theta = c$.
The solution to this problem is to make $q$ as large as possible wherever $p$ is large, and as small as possible wherever
$p$ is small. To be precise, if we put 
$$\begin{eqnarray}
y &=& \inf \left\{ z \mid \lambda(p \ge z) \le \frac{c-a}{b-a} \right\} \\
A &=& \{\theta \in [0,1] \mid p(\theta) < y \} \\
B &=& \{\theta \in [0,1] \mid p(\theta) > y \} \\
\end{eqnarray}
$$
then a function $q$ satisfying the constraints is a maximizer iff
$q(\theta) = a$ almost everywhere in $A$ and $q(\theta) = b$ almost everywhere in $B$. Thus maximizers are essentially
unique if $\lambda([0, 1]\setminus A \setminus B)$ = 0. 
The only relevant property of $[0,1]$ is that it is a finite measure space,
so this should carry over without any problem to the multidimensional case.
