LCC/Moose '20 Contest 5 J5 - O-Mo-Te-Na-Si

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Andy is now a god at mixing and wants to make some very reactive mixtures.

He has put together an assortment of N (1 \le N \le 2\cdot10^5) different solutions. Each has 2 key traits he will consider. The i^{th} solution has a pH of a_i and an attractiveness of b_i (-10^9 \le a_i, b_i \le 10^9).

Andy will choose K (1 \le K \le N) of these solutions and mix them together. The total pH is the sum of the pH's of the solutions he selects. The total attractiveness is the sum of the attractivenesses of the solutions he selects.

He defines the reactivity of a mixture as the sum of the absolute value of the total pH and the absolute value of the total attractiveness of the mixture. What is the maximum reactivity that Andy can achieve?

Input Specification

The first line contains two integers N and K.

The next N lines will each contain two integers, a_i,\ b_i.

Output Specification

Output one integer, the maximum reactivity.

Subtasks

Subtask 1 [30%]

N \le 20

Subtask 2 [70%]

No further constraints.

Sample Input 1

3 2
6 -12
5 11
-1 0

Sample Output 1

17

Sample Explanation 1

He should mix the first and third solutions. The total pH is 6+(-1)=5. The total attractiveness is (-12)+0=-12. The reactivity of the mixture is |5|+|-12|=17.

Sample Input 2

5 3
363756450 712662868
735867677 193944314
586260100 -192321079
95834122 802780784
418379342 -790013317

Sample Output 2

2904846215

Comments

There are no comments at the moment.