Existence of k-media and medians