Closed form solutions for water-filling problems in optimization and game frameworks