Problem
Find a solution to the congruences:
$$y \equiv m_1x + b_1 \pmod p$$
$$y \equiv m_2x + b_2 \pmod p$$
when $m_1 \not\equiv m_2 \pmod p$.
Solution attempt
From the given congruences for $y$, it follows that:
$$m_1x + b_1 \equiv m_2x + b_2 \pmod p$$
Adding $-m_2x-b_1$ to both sides:
$$m_1x - m_2x \equiv b_2 - b_1 \pmod p$$
$$(m_1 - m_2)x \equiv b_2 - b_1 \pmod p$$
Since $m_1 \not\equiv m_2 \pmod p$, then $m_1 - m_2 \not\equiv 0 \pmod p$. Since $p$ is a prime, this implies that $\mathrm{gcd}(m_1 - m_2, p) = 1$. Therefore, the multiplicative inverse of $m_1 - m_2$ modulo $p$ exists. Call it $r$. Multiplying both sides of the above congruence by $r$:
$$x \equiv (b_2 - b_1) r \pmod p$$
$y$ can then be found by substituting the above expression for $x$ in one of the original congruences. Substituting it in $y \equiv m_1x + b_1 \pmod p$:
$$y \equiv m_1((b_2 - b_1) r) + b_1 \pmod p$$
The value of $r$ can be found as follows: since $\mathrm{gcd}(m_1 - m_2, p) = 1$, then, by Bézout's lemma, $a(m_1 - m_2) + bp = 1$ for some $a$, $b$ (the values of $a$ and $b$ can be calculated using the extended Euclidean algorithm). Then, it follows that:
$$a(m_1 - m_2) + bp \equiv 1 \pmod p$$ $$a(m_1 - m_2) \equiv 1 \pmod p$$
The above means that $a$ (or any other integer that is congruent to $a$ modulo $p$) is an inverse modulo $p$ of $m_1 - m_2$. So, let $r = a$, and the expressions for $x$ and $y$ become:
$$x \equiv (b_2 - b_1) a \pmod p$$
$$y \equiv m_1(b_2 - b_1) a + b_1 \pmod p$$
Could someone verify if my attempt is correct? Thank you.