Algorithm which finds the maxmal solution that satisfies the following constraints
You want a solution $x$ such that

$$x \equiv b_i \pmod{a_i}$$

for all $i$.  By the Chinese remainder theorem, this is either impossible or it is equivalent to

$$x \equiv b \pmod{a}$$

where $a = \text{lcm}(a_1,\dots,a_n)$ and $b$ can be computed using the Chinese remainder theorem.  In other words, the solutions are all of the form $b$, $b+a$, $b+2a$, $b+3a$, etc.  From there it is easy to find the largest solution $x$ such that $x\le U$.