Maximize $P=a^2+b^2+c^2+ab+ac+bc$ 
For real numbers $a, b, c$ that  satisfy $a + b + c = 6$ and $0\leq a,b,c \leq 4$, 
  maximize $P=a^2+b^2+c^2+ab+ac+bc$. 

My try:

$$\begin{align} \begin{cases} a+b+c=6(1) \\ 0\leq a,b,c\leq4(2) \end{cases} \end{align}$$ $$(1)\Rightarrow \begin{align} \begin{cases} b+c=(6-a) \\b^2+c^2+bc=(6-a)^2-bc \end{cases} \end{align}$$ $$P=a^2+(b^2+c^2+bc)+a(b+c)=a^2+[(6-a)^2-bc]+a(6-a)$$ $$P=(a^2-12a+36)-bc=(a-6)^2-bc (2)\Rightarrow bc\leq 0 \Rightarrow P\geq (a-6)^2$$ When $bc=0 \Rightarrow [{\begin{matrix}b=0\\c=0\end{matrix}}(3)$. From  $(1)$ and $(3)$,  $\Rightarrow 2\leq a\leq 4(4)$ $P_{max} \implies |a-6|$ max satisfy $(4)$ $\implies a=2$ from $(1)$ and $(3)$ $\implies b=c=4$ $\implies P_{max}(a,b,c)=P(4;2;0)=28$

 A: From the fact that $a+b+c=6$, we know that $$36=\left( \sum_{cyc} a \right)^2=\sum_{cyc}a^2+2 \sum_{cyc}ab=P+\sum_{cyc}ab$$
So maximizing $P$ becomes equivalent to minimizing $ab+bc+ca$. 
WLOG, assume that $a$ is the maximum among $a,b,c$. So $a+b+c =6 \le 3a$, hence $4 \ge a \ge 2$ from the condition. 
However, note that $$ab+bc+ca \ge ab+ca= a(b+c)=a(6-a) \ge 8$$
From $4 \ge a \ge 2$. 
Hence the minimum of $ab+bc+ca=8$, when $a=4,b=2, c=0$. Thus, the maximum of $P$ is $36-8=28$. 
We are done!
A: The stationary points of a quadratic form over a triangle (or hexagon) are simple to locate through Lagrange's multipliers. Your quadratic form is positive definite with eigenvectors $(1,1,1)$, $(-1,0,1)$, $(-1,1,0)$ hence the maximum value is attained on the boundary of the given domain, by convexity. By analyzing the instances $a=0$ and $a=4$ we easily get that the maximum is $28$, attained at $\{a,b,c\}=\{0,2,4\}$.
A: Let $f(x)=x^2$ and $a\geq b\geq c$. 
Hence, $f$ is a convex function and $(4,2,0)\succ(a,b,c)$. 
Thus, by Karamata
$$\sum_{cyc}(a^2+ab)=a^2+b^2+c^2+\frac{36-a^2-b^2-c^2}{2}=\frac{1}{2}(a^2+b^2+c^2)+18\leq$$
$$\leq\frac{1}{2}(4^2+2^2+0^2)+18=28.$$
Done!
