Art Academy II: The Grand Escape

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 3.0s
Memory limit: 64M
PyPy 2 128M
PyPy 3 128M

Author:
Problem type

After being trapped inside of hewmatt10's basement "Art Academy", astrocat879 decided that it was finally time for him to plan an escape. Fortunately, hewmatt10 had never considered the possibility of his loyal partner wanting to escape, so the actual escape would be a piece of cake.

Along the Academy, there are a total of N paintings spread across the area, each with a value of vi. Since astrocat879 is short on money, he plans to steal some of the paintings while making his escape. However, all of his paintings' values have been hashed, meaning that the value that astrocat879 sees them at is NOT the actual value. Specifically, the paintings' values have been hashed using the following function:

hash(i)=i×2654435761mod232

(hash(i) represents the hashed value, while i represents the original value. It is guaranteed that all integer values of i under 232 will be given a unique hash value.)

astrocat879 doesn't have the time to figure out the original value of the paintings, and so has asked YOU to create a program for him that will maximize his profits. More specifically, he would like you to sum up the M paintings with the greatest original value.

Input Specification

On the first line, there will be two space-separated integers, N and M (1MN3×105). The next N lines will contain a single integer vi, representing the hashed value of the ith painting. It is guaranteed that the original value of this hashed number will be greater than 0, but no greater than 231.

Output Specification

A single integer, representing the sum of the M paintings with the greatest original value.

Constraints

Subtask 1 [10%]

1N102

i216

Subtask 2 [10%]

1N102

Subtask 3 [80%]

No additional constraints.

Sample Input

Copy
5 2
387276917
145972072
2654435761
147926525
2415085369

Sample Output

Copy
1013

Explanation

The original values for the paintings with values 387276917, 145972072, 2654435761, 147926525, and 2415085369, are 5, 1000, 1, 13, and 9, respectively.

The sum of the two greatest values, 1000 and 13, is 1013.


Comments

There are no comments at the moment.