Submit | All submissions | Best solutions | Back to list |
CDGLF1 - Kejriwal And Broom |
Kejriwal And Broom
Once Kejriwal went to a sale of old brooms. There were ‘n’ brooms at that sale. Broom with index ‘i’ costs ‘ai’ . Some brooms are so useless that they have a negative price ie. their owners are ready to pay Kejriwal if he buys those brooms. Kejriwal can buy any broom(s) he wants. Though he's very strong but can carry at most ‘m’ brooms only, and he has no desire to go to the sale for the second time. Please, help Kejriwal find out the maximum sum of money that he can earn.
Input
The first line contains ‘t’-number of test cases.Each test case contains two space-separated integers ‘n’ and ‘m’ — amount of brooms at the sale, and amount of brooms that Kejriwal can carry and the following line contains ‘n’ space-separated integers ‘ai’ — prices of the brooms
Output
Output the only number — the maximum sum of money that Kejriwal can earn, given that he can carry at most ‘m’ brooms.
Constraints
-
1<=t<=100
-
1<=m<=n<=100
-
-1000<=ai<=1000
Sample Input
2
5 3
-6 0 35 -2 4
4 2
7 0 0 -7
Sample Output
8
7
Added by: | CSI |
Date: | 2015-02-11 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 JS-MONKEY |
hide comments
2019-06-18 15:51:16
Input Data is badly prepared. Got many NZECs, cause there is too many spaces sowhere, and you need too use Trim() function to remove it. |
|
2015-08-25 17:05:41 abhinav
It should be mentioned here that points are given on the basis of source code length. |
|
2015-03-04 07:58:18 Mitch Schwartz
1) Constraints should not be increased after so many solvers. 2) It doesn't seem that increasing constraints would make the problem more interesting. 3) Your question is a spoiler. 4) Your question shows that you did not fully analyse the problem. --> Your comment is hidden. |
|
2015-02-13 20:40:15 Mitch Schwartz
Moved CDGLF* problems to challenge, as they can't be in classical because of scoring. (But I didn't read the problems yet, to check for quality control issues.) |