World Burn
Her boyfriend left her. The Plastics left her. Now, Regina George just wants to watch the world burn.
Her weapon? The Burn Book — a book of insults and roasts. Each page targets one person from school and comes with a "burn value" . Regina can select at most
pages to copy and post all over the school.
Being burned sucks. Being burned multiple times sucks more. For any person, the total pain they suffer is calculated as:
For example, if Regina posts pages about Janis with burn values
,
, and
, Janis suffers
pain.
Given all the pages Regina has, and the limit on how many she can choose, what's the maximum total pain she can inflict?
Input
The first line consists of an integer
, the number of pages Regina has at her disposal.
The next line consists of an integer
, the number of pages Regina can choose to disperse in the halls.
The next lines consist of
and
, where
is person being insulted, and
is the insult's burn value.
can be any string of English characters.
Output
Output the total amount of pain that Regina can inflict onto her peers.
Example
Input
7
4
Janis 2
Janis 5
Janis 4
Trang 2
Trang 1
Regina 15
Damien 6
Output
48
Regina can release all pages about Janis, which inflicts
pain overall.
She can then release the
page about herself, which inflicts
pain. Overall, she has inflicted
pain, which is the maximum in this case.
Comments