Let pi : X -> Y be a factor map, where (X, sigma(X)) and (Y, sigma(Y)) are subshifts over finite alphabets. Assume that X satisfies weak specification. Let a = (a(1), a(2)) epsilon R-2 with a(1) > 0 and a(2) >= 0. Let f be a continuous function on X with sufficient regularity (Holder continuity, for instance). We show that there is a unique shift invariant measure mu on X that maximizes integral f d mu + a(1)h(mu) (sigma(X)) + a(2)h(mu o pi-1) (sigma(Y)). In particular, taking f equivalent to 0 we see that there is a unique invariant measure mu on X that maximizes the weighted entropy a(1) h(mu) (sigma(X)) + a(2)h(mu o pi-1) (sigma(Y)), which answers an open question raised by Gatzouras and Peres (1996) in [15]. An extension is given to high dimensional cases. As an application, we show that for each compact invariant set K on the k-torus under a diagonal endomorphism, if the symbolic coding of K satisfies weak specification, then there is a unique invariant measure mu supported on K so that dim(H) mu = dim(H) K. (c) 2010 Elsevier Inc. All rights reserved.