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

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 v_i. 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:

\displaystyle hash(i)=i \times 2654435761 \bmod 2^{32}

(hash(i) represents the hashed value, while i represents the original value. It is guaranteed that all integer values of i under 2^{32} 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 (1 \le M \le N \le 3 \times 10^5). The next N lines will contain a single integer v_i, representing the hashed value of the i^\text{th} painting. It is guaranteed that the original value of this hashed number will be greater than 0, but no greater than 2^{31}.

Output Specification

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


Subtask 1 [10%]

1 \le N \le 10^2

i \le 2^{16}

Subtask 2 [10%]

1 \le N \le 10^2

Subtask 3 [80%]

No additional constraints.

Sample Input

5 2

Sample Output



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.


There are no comments at the moment.