Let $E$ be a finite set and let $\mathcal I\subset 2^E$ be a nonempty hereditary family, whose maximal members under inclusion are called bases. For a weight function $w:E\to \mathbb R_{\ge 0}$, consider any ordering of $E$ by nonincreasing weight and let the greedy algorithm successively add an element exactly when the resulting set remains in $\mathcal I$. For every such $w$ and every such nonincreasing ordering, this algorithm returns a maximum-weight basis if and only if $(E,\mathcal I)$ is a matroid.