\(B=-x^2-y^2+xy+2x+2y\)
\(\Rightarrow-2B=2x^2+2y^2-2xy-2x-4y\)
\(=\left(x^2-2xy+y^2\right)+\left(x^2-4x+4\right)+\left(y^2-4y+4\right)-8\)
\(=\left(x-y\right)^2+\left(x-2\right)^2+\left(y-2\right)^2-8\)
vì \(\left(x-y\right)^2\ge0\forall x,y;\left(x-2\right)^2\ge0\forall x;\left(y-2\right)\ge0\forall y\)nên
\(-2B=\left(x-y\right)^2+\left(x-2\right)^2+\left(y-2\right)^2-8\ge8\)
hay \(-2B\ge-8\Rightarrow B\le4\)
\(\Rightarrow maxB=4\Leftrightarrow\hept{\begin{cases}x-y=0\\x-2=0\\y-2=0\end{cases}\Leftrightarrow\hept{\begin{cases}x=y\\x=2\\y=2\end{cases}}}\)