VM7WC '15 #3 Silver - Test Scores

View as PDF

Submit solution

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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
    selimturkmen  commented on Feb. 10, 2020, 2:47 p.m.


  • -3
    jaydenchu2003  commented on Jan. 24, 2020, 2:04 p.m. edited

    Screw this damn question

    Can't even get more than one AC

  • 3
    BMP  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?

    • 5
      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.

      • 1
        IanHu  commented on Dec. 25, 2018, 10:54 p.m.

        Thank you!

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

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

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

    can Mr. White send in no scores at all?

    • 1
      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?