Let \((\Sigma ,g)\) be a closed Riemann surface, \(\lambda _1(\Sigma )\) be the first eigenvalue of the Laplace-Beltrami operator. Assume \(h:\Sigma \rightarrow \mathbb {R}\) is some smooth sign-changing function. Using blow-up analysis, we prove that for any \(\alpha <\lambda _1(\Sigma )\) , the supremum \(\sup _{\int _\Sigma |\nabla _gu|^2dv_g-\alpha \int _\Sigma u^2dv_g\le 1,\,\int _\Sigma udv_g=0}\int _\Sigma he^{4\pi u^2}dv_g\) is attained by some admissible function \(u_\alpha \) . This generalizes earlier results of Yang (J. Differential Equations 2015) and Hou (J. Math. ineq. 2018). Our result resembles existence of solutions to the mean field equations \(\Delta _gu=8\pi \left( \frac{he^u}{\int _\Sigma he^udv_g}-\frac{1}{|\Sigma |}\right) ,\) where h is a smooth sign-changing function. Such problems were extensively studied by L. Sun and J. Y. Zhu (Cal. Var. 2021; arXiv: 2012.12840).