Let's brush up pipelining a bit. To summarize, the goal of pipelining is to make the clocks per instruction (CPI) approach $1$, which means that as you keep increasing the number of instructions they take only $1$ clock cycle(which is the time taken by the slowest stage in the pipeline) to complete.
Assume you have a single instruction. Now, to complete it's execution this must go through all the $k$ stages of the pipeline(including the buffer delays & in this case $5$ stages) so it takes $k$ clock cycles to complete. Now lets take $2$ instructions, naturally both of them have to pass through the complete pipeline to complete their execution. Here is where the pipelining shows its benefits. As the first instruction moves from $stage$ $1$ to $stage$ $2$, simultaneously the second instruction enters $stage$ $1$. Its easy to infer that when the first instruction would be at stage $k$, the second would be right behind it at stage $k-1$ (assuming no stalls). So now the first instruction completes at $kth$ clock cycle and the second instruction at $k+1th$ clock cycle.
Generalizing it, when you have n instructions, the $1st$ one will always be completed at the $kth$ clock cycle, and the remaining $n-1$ instructions would get completed at subsequent $n-1$ clock cycles as each of them would take only $1$ clock cycle to complete, giving a total of $k+n-1$ clock cycles. $tp$ is the multiplicative factor, which here is the time taken by $1$ clock cycle. Take note that all the instructions take the complete time of the whole pipeline to execute, but since we do not let the pipeline sit idle, the overall completion time is greatly reduced, which is what pipelining aims at.
My Question In the above solution why we are using the formula for total time is like that. We can use something like:
tp*(n-1) + (sum of delays in all stages)
Well you are correct, as I mentioned the $1st$ instruction would be completed at the $kth$ clock cycle, which is after passing through all the $k$ stages and their delays, which turns out to be $k*tp$, and the complete expression becomes $tp*(n-1)+k*tp$ which is the same as $(k+n-1)*tp$.