VM7WC '15 #3 Silver - Test Scores

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

After landing a job in a math empire, Mr. White's first task is to grade Massey students' Putnam contests. In total, there are N (1 \le N \le 100\,000) contests that require marking, each with a certain score associated with them. Since the contest is so difficult, it is possible for students to get negative marks.

Furthermore, Mr. White can only send in up to K (1 \le K \le N) of the contests. Help Mr. White find the maximum sum of scores that he can send in.

Input Specification

The first line contains two space-separated integers N and K.

This is followed by N lines, each containing a single integer, describing the contest scores.

Output Specification

Print a single integer, the maximum sum of up to K contest scores. The answer will be guaranteed to fit inside of a 32-bit signed integer.

Sample Input

5 2
5
2
7
5
3

Sample Output

12

Comments


  • 1
    omaewamoushindeiru  commented on Jan. 23, 2015, 6:48 p.m.

    do they scores have to be adjacent to each other, or just add the top k?


    • 5
      bobhob314  commented on Jan. 23, 2015, 7:03 p.m.

      Just going to say, you're getting something else wrong that you would probably figure out without me mentioning it but I want to sound smart.

      Anyway,

      "it is possible for students to get negative marks."

      so as a "so-I-don't-get-banned-again" example, if BMP is really bad at computer programming and would only make his ECOO team worse if he was sent, and ECOO teams should have 4 people, and including BMP there are only 4 people who want to take ECOO, then maybe it's better to kick BMP out of the team.


      • 0
        IanHu  commented on Dec. 26, 2018, 3:54 a.m.

        Thank you!


      • 3
        omaewamoushindeiru  commented on Jan. 23, 2015, 7:06 p.m.

        he can send !!!!up-to!!!!


  • 0
    Derifos  commented on Jan. 22, 2015, 11:07 p.m.

    can Mr. White send in no scores at all?


    • 0
      thorthugnasty  commented on Jan. 23, 2015, 1:11 a.m.

      Yes.


      • -3
        bobhob314  commented on Jan. 23, 2015, 1:37 a.m.

        Another question: Is it possible to post images or gifs in comments?