In the first test, the optimal solution will be to perform the following operations:
\begin{enumerate}
\item apply the operation to the 2nd task: assign $a_2:=a_2-1$ after this the array will become equal to $[2,2,5,1,2]$;
\item apply the operation to the 3rd task: assign $a_3:=a_3-1$ after this the array will become equal to $[2,2,4,1,2]$;
\item apply the operation to the 3rd task: assign $a_3:=a_3-1$ after this the array will become equal to $[2,2,3,1,2]$;
\item apply the operation to the 3rd task: assign $a_3:=a_3-1$ after this the array will become equal to $[2,2,2,1,2]$;
\item apply the operation to the 4th task: assign $a_4:=a_4+1$ after this the array will become equal to $[2,2,2,2,2]$;
\end{enumerate}

It can be shown that obtaining an answer less than $5$ is not possible.