Maximum matching of given weight in complete and complete bipartite graphs