\(D=\left(x-1\right)^2-\left(2x+1\right)^2+2018\)
\(=x^2-2x+1-4x^2-4x-1+2018\)
\(=-3x^2-6x+2018=-3\left(x^2+2x+1\right)+2021\)
\(=-3\left(x+1\right)^2+2021\)
Vì \(-3\left(x+1\right)^2\le0\Rightarrow D\le2021\)
Dấu ''='' xảy ra \(\Leftrightarrow x=-1\)
Vậy \(Max_D=2021\Leftrightarrow x=-1\)