Problem link: http://www.codechef.com/AUG13/problems/LELEMON
Little Elephant likes lemonade.
When Little Elephant visits any room, he finds the bottle of the lemonade in that room that contains the greatest number of litres of lemonade and drinks it all.
There are n rooms (numbered from 0 to n-1), each contains bottles. Each bottle has a volume (in litres). The first room visited by Little Elephant was th, the second th, …, the m-th th room. Note that Little Elephant may visit a room more than once.
Find for Little Elephant the total volume of lemonade he has drunk.