A universal quantum algorithm for weighted maximum cut and Ising problems