In the game Primogem Gacha Impact No. 3, players can spend in-game currency for the chance to obtain any of the game's characters. However, with the passing of a new law banning the gacha mechanic at Bayview Secondary School, the game has been altered to allow players to deterministically buy characters. Specifically, the character now costs units of in-game currency to buy, where is the number of other characters the player owns at the time of purchase.
You want to assemble a team of different characters, but since you're running low on money to whale, you want to do this for as cheap as possible, regardless of what team you end up with. Given that you can buy the characters in any order, what is the minimum cost to obtain a team of characters?
Subtask 1 [30%]
Subtask 2 [70%]
No additional constraints.
The first line contains two integers, and , the total number of characters in the game and the size of the team you wish to assemble.
The next lines contain two integers each, and .
Output a single integer, the minimum cost to buy a team of characters.
4 2 1 2 3 2 1 4 2 1
You can buy the fourth character for a cost of , then the first character for a cost of . In total, this costs units of currency. This is the minimum required to buy two characters.