The main objective of this work is to bring together two well known and, a priori, unrelated theories dealing with weighted inequalities for the Hardy-Littlewood maximal operator $M$. For this, the authors consider the boundedness of $M$ in the weighted Lorentz space $Lambdap u(w)$. Two examples are historically relevant as a motivation: If $w=1$, this corresponds to the study of the boundedness of $M$ on $Lp(u)$, which was characterized by B. Muckenhoupt in 1972, and the solution is given by the so called $A p$ weights. The second case is when we take $u=1$. This is a more recent theory, and was completely solved by M.A. Arino and B. Muckenhoupt in 1991. It turns out that the boundedness of $M$ on $Lambdap(w)$ can be seen to be equivalent to the boundedness of the Hardy operator $A$ restricted to decreasing functions of $Lp(w)$, since the nonincreasing rearrangement of $Mf$ is pointwise equivalent to $Af*$. The class of weights satisfying this boundedness is known as $B p$. Even though the $A p$ and $B p$ classes enjoy some similar features, they come from very different theories, and so are the techniques used on each case: Calderon-Zygmund decompositions and covering lemmas for $A p$, rearrangement invariant properties and positive integral operators for $B p$. This work aims to give a unified version of these two theories. Contrary to what one could expect, the solution is not given in terms of the limiting cases above considered (i.e., $u=1$ and $w=1$), but in a rather more complicated condition, which reflects the difficulty of estimating the distribution function of the Hardy-Littlewood maximal operator with respect to general measures.