We will first calculate the total price of rice we have:
12kg * 35 Rs/kg + 8kg * 45 Rs/kg = 780 Rs
(Note the kg unit cancelling out :) )
Now, we know we have 8kg + 12kg = 20kg of rice costing a total of 780 Rs. We want the price per kg, so we simply divide 780 Rs by 20 kg:
780 Rs / 20 kg = 39 Rs/kg