VM7WC '15 #3 Silver - Test Scores

View as PDF

Submit solution

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

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

Sample Output



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

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

    • 6
      bobhob314  commented on Jan. 23, 2015, 2: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.


      "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. 25, 2018, 10:54 p.m.

        Thank you!

      • 4
        omaewamoushindeiru  commented on Jan. 23, 2015, 2:06 p.m.

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

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

    can Mr. White send in no scores at all?

    • 0
      thorthugnasty  commented on Jan. 22, 2015, 8:11 p.m.


      • -2
        bobhob314  commented on Jan. 22, 2015, 8:37 p.m.

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