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 Xi 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 (1MN105), the number of farms, and the number of farms Yunji has to sell, respectively.

The next line will contain N integers, Xi (1Xi105).

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%]

Mmin(50,N)

Subtask 2 [85%]

No additional constraints.

Sample Input 1

Copy
2 1
8 10

Sample Output 1

Copy
10

Sample Input 2

Copy
3 3
29 34 12

Sample Output 2

Copy
0

Comments


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

    guys, remember to use 263 integer data type to store your sum, using normal 231 integer data types is not enough for this question