Lem0nad3's Bar
Time limit4sMemory limit512 MB
Choose at most K lemonades and the times to drink them so that the total of each fizz level times a drink-order weight is maximized.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Greedy
- Solved
- No attempts yet
Problem
Geunsu has solved countless problems and is exhausted, so he goes into a lemonade bar to rest.
The bar has lemonades. Lemonade comes out at time with a fizz level of . The carbonation fades as time passes, so the fizz level drops by 1 for every unit of time. At time (), the fizz level of lemonade is .
Geunsu has a thirst level of , so he can drink at most lemonades. A lemonade drunk while thirsty gives more happiness. The first lemonade he drinks gives happiness equal to times its fizz level. The second gives times its fizz level, and the -th lemonade he drinks gives times its fizz level. In other words, if lemonade is the -th one he drinks, and he drinks it at time (), his happiness increases by .
Drinking takes negligible time. Several lemonades can be drunk at the same time, in any order.
Geunsu starts with 0 happiness. Drink the lemonades in the best way to give Geunsu the maximum happiness.
Input
The first line contains and , separated by a space. (; )
Each of the next lines contains and , separated by a space. ()
Output
Print the maximum happiness Geunsu can obtain.