Solution (source code)

= Solution

Use <round-robin scheduling> with <scheduling quantum> 2 ms. A's first burst is split by B, and A's second burst is also interrupted once. The resulting CPU intervals are
$$
\begin{array}{c|rrrrrrrrrrr}
\text{interval}&0\!:\!2&2\!:\!3&3\!:\!5&5\!:\!6&6\!:\!7&7\!:\!9&9\!:\!10&10\!:\!12&12\!:\!14&14\!:\!16&16\!:\!18\\
\text{CPU}&A&B&A&B&\text{idle}&A&B&A&\text{idle}&A&A
\end{array}
$$
A blocks for input-output during $[5,7)$ and $[12,14)$; B blocks during $[3,5)$ and $[6,8)$. At time 8, B joins the <ready queue> while A uses the remainder of its current quantum; B runs at time 9. No other process is runnable during A's final four milliseconds, so A can continue across the time-16 quantum boundary. Consequently
$$
\boxed{C_B=10,\quad C_A=18,\quad\text{elapsed time}=18\text{ ms},\quad\text{mean turnaround}=14\text{ ms}.}
$$