GlobeX Cup '18 J Sample - Farming Simulator

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Farmer Yunji owns N farms. Each farm produces X_i dollars per day. Due to tax issues, he has to sell M of his farms. What is the maximum amount of money he can earn per day from his farms, after he sells M of them?

Input Specification

The first line will contain two space-separated integers, N, M (1 \le M \le N \le 10^5), the number of farms, and the number of farms Yunji has to sell, respectively.

The next line will contain N integers, X_i (1 \le X_i \le 10^5).

Output Specification

On the first line, output the maximum amount of money Yunji can make per day after selling M of his farms.

Constraints

Subtask 1 [15%]

M \le \min(50,N)

Subtask 2 [85%]

No additional constraints.

Sample Input 1

2 1
8 10

Sample Output 1

10

Sample Input 2

3 3
29 34 12

Sample Output 2

0

Comments


  • 3
    magicalsoup  commented on Dec. 7, 2018, 11:34 p.m. edited

    guys, remember to use 2^{63} integer data type to store your sum, using normal 2^{31} integer data types is not enough for this question