Existence of minimizers and maximizers