4. For a procrastinator, the waiting time will increase by $a$ minutes.

Therefore, the total wasted time of all standing in the queue will decrease by $b-a$ minutes. We will thus swap people in pairs of "Procrastinator-Hurry" until we get a queue where all the hurries stand before all the procrastinators. In this queue, the wasted time will be minimal.

Let's find the total wasted time. The second person waits for the first, the third waits for the previous two, and so on.

The total time spent waiting for all the hurries in front to finish their operations is

$$
(a+2a+\ldots+(n-1)a)+m \cdot n a=a \cdot \frac{1+n-1}{2} \cdot(n-1)+m n a=a C_{n}^{2}+m n a
$$

Here, the term $m n a$ is the total time spent by all procrastinators waiting for all the hurries.

The total time spent waiting for the procrastinators in front to finish their operations is $b+2b+\ldots+(m-1)b=b C_{m}^{2}$.

The overall minimum waiting time for all customers is

$$
T_{\min }=a C_{n}^{2}+a m n+b C_{m}^{2}
$$

In our specific case, we get:

$$
1 \cdot C_{5}^{2}+1 \cdot 5 \cdot 3+5 \cdot C_{3}^{2}=10+15+15=40
$$[^3]

Similarly, it can be proven that the maximum wasted time will be if all procrastinators stand before all hurries. This time is

$$
T_{\max }=a C_{n}^{2}+b m n+b C_{m}^{2}
$$

With the numerical data from the problem, we get $1 \cdot C_{5}^{2}+5 \cdot 5 \cdot 3+5 \cdot C_{3}^{2}=10+75+15=100$.

b) Consider the $k$-th customer in the queue. Let $X_{k}$ be the number of procrastinators standing before him. Then $X_{k}=I_{1}+I_{2}+\ldots+I_{k-1}$, where the indicator $I_{j}$ takes the value 1 if the $j$-th customer is a procrastinator and 0 if the $j$-th customer is a hurry.

The $j$-th customer can be a procrastinator with probability $\frac{m}{m+n}$ and a hurry with probability $\frac{n}{m+n}$. Therefore, $\mathrm{E} I_{j}=0 \cdot \frac{n}{m+n}+1 \cdot \frac{m}{m+n}=\frac{m}{m+n}$.

Thus, $\mathrm{E} X_{k}=\frac{(k-1) m}{m+n}$.

Let $T_{k}$ be the waiting time of the $k$-th customer. We get:

$$
T_{k}=X_{k} b+\left(k-1-X_{k}\right) a=(b-a) X_{k}+a(k-1)
$$

Therefore,

$$
\mathrm{E} T_{k}=(b-a) \mathrm{E} X_{k}+a(k-1)=(b-a) \cdot \frac{(k-1) m}{m+n}+a(k-1)=\frac{b m+a n}{m+n} \cdot(k-1)
$$

Summing the obtained expression over all customers from 1 to $m+n$-th, we get the expected total wasted time:

$$
\begin{gathered}
\mathrm{E} T=\mathrm{E}\left(T_{1}+T_{2}+\ldots+T_{n}\right)=\frac{b m+a n}{m+n} \cdot(0+1+2+\ldots+(m+n-1))= \\
=\frac{(b m+a n)(n+m-1)}{2}=C_{n+m}^{2} \cdot \frac{b m+a n}{m+n}
\end{gathered}
$$

Substituting the known numbers from the condition: $C_{8}^{2} \cdot \frac{5 \cdot 3+1 \cdot 5}{8}=\frac{7 \cdot 20}{2}=70$.
Answer: a) 40 minutes and 100 minutes; b) 70 minutes.

Comment. The expected time turned out to be the arithmetic mean between the maximum and minimum possible. Try to prove the fact $\mathrm{E} T=\frac{T_{\min }+T_{\max }}{2}$ in general, that is, prove the combinatorial identity

$$
C_{n+m}^{2} \cdot \frac{b m+a n}{m+n}=a C_{n}^{2}+\frac{a+b}{2} m n+b C_{m}^{2}
$$

By the way, part b) could have been solved almost without calculations, by noting that each arrangement of slowpokes and hurries can be matched with a symmetrically equal and equally probable arrangement, and the sum of the waiting times for both arrangements will be equal to $a C_{n}^{2}+\frac{a+b}{2} \cdot m n+b C_{m}^{2}$. For this, it is convenient to use the graphical method (see the footnote above).