Let $\lambda \in [0,1]$, $c \geq 0$. I want to find the quadratic functions $P: \mathbb{R}\rightarrow \mathbb{R}$ with $P(0)=0$ for which there exist $\bar{q}_P, \hat{q}_P \geq 0$ such that $P'(\bar{q}_P)+\bar{q}_P=1$ and $\frac{P(\hat{q}_P)}{\hat{q}_P}+\hat{q}_P=1$ that maximizes $$J(P):=\int_0^{q_{P}^*} {(P'(q)-c)(1+q-\lambda \frac{P(q)}{q}-(1-\lambda)P'(q))dq}$$ where $q_{P}^*:=\min \left\{{\bar{q}_P, \hat{q}_P}\right\}$.
My idea is to apply the Euler Lagrange equation to the function $$H(q,P(q),P'(q),P'''(q)):=L(q,P(q),P'(q))+\mu(q)P'''(q)$$ where $L(q,P(q),P'(q)):=(P'(q)-c)(1+q-\lambda \frac{P(q)}{q}-(1-\lambda)P'(q))$ and $\mu(q)$ is the Lagrange multiplicator associated to the restriction $P'''(q)=0$ for all $q \in [0,q_{P}^*]$, and then verify that the optimal $P$ satisfies the required conditions.
After apply the Euler Lagrange equation, I obtained the following differential equation: $$-\mu'''-\frac{\partial}{{\partial q}}\frac{{\partial L}}{{\partial P'}}+\frac{{\partial L}}{{\partial P}}=0$$.
By my problem is that the restriction $P'''=0$ and the previous differential equation allows different functional form choices for $\mu$ and $P$.