409144: GYM103446 I Steadily Growing Steam
Description
Alice enjoys playing a card game called Steadily Growing Steam (as known as SGS).
In this game, each player will play different roles and have different skills. Players get cards from the deck and use them to play the game. Each card has a numeric label $$$t_i$$$, the point number. In addition, each card has a value $$$v_i$$$.
Now Alice is playing this game with Bob. According to the skill of Alice's role, she can have Bob display $$$n$$$ cards from the top of the deck. After that, Bob must choose some cards from the $$$n$$$ cards and split the chosen cards into two sets that the sum of the cards' point numbers in the two sets are equal. In other words, if one of the sets is $$$S$$$ and another is $$$T$$$ , $$$S\cap T=\emptyset$$$ and $$$\sum_{i\in S} t_i=\sum _{j\in T}t_j$$$ (Note that $$$S\cup T = \{1,2,\cdots n\}$$$ is not necessary). Then, Alice gets all of the cards in set $$$S$$$ and Bob gets the cards in set $$$T$$$.
However, according to the skill of Bob's role, before choosing the two sets, he can choose at most $$$k$$$ different cards and double their point numbers. In other words, he can choose a sequence $$$\{a_1,a_2,\cdots,a_r\},\,(1\le a_1<a_2<\cdots <a_r\le n,\, 0\le r\le k)$$$ and for each $$$i\,(1\le i \le r)$$$ , change $$$t_{a_i}$$$ into $$$2t_{a_i}$$$. After that he can continue choosing the two sets.
Alice and Bob are partners in this game. Now given the $$$n$$$ cards from the deck, they want to know the maximum possible sum of the values of the cards they finally get. In other words, determine the maximum $$$\sum_{i\in S \cup T}v_i$$$ among all valid schemes(choose cards to double their point numbers, then choose cards and split them into two sets $$$S,T$$$ of the same point number sum) and output it.
InputThe first line contains two integers $$$n\,(1\le n \le 100)$$$ and $$$k\,(0\le k \le n)$$$, denoting the number of the displayed cards and the maximum number of cards that Bob can choose to double their point numbers, respectively.
The $$$i+1$$$ line contains two integers $$$v_i\,(|v_i|\le 10^9)$$$ and $$$t_i\,(1\le t_i \le 13)$$$, denoting the value and the point number of the $$$i$$$-th card, respectively.
OutputOutput one line containing one integer, denoting the maximum sum of the value of the cards that Alice or Bob can get.
ExampleInput4 1 10 1 -5 3 5 1 6 1Output
21Note
One possible scheme:
Double $$$t_1$$$ and choose that $$$S=\{1\},T=\{3,4\}$$$, where the point number sum are both 2, and the sum of the card values is $$$10+5+6=21$$$.