Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getGets = (arr) => {
- let index = 0;
- return () => {
- const toReturn = arr[index];
- index += 1;
- return toReturn;
- };
- };
- // this is the test
- const test = [
- 8, 3, 3, 2, 3, -2, 5, 4, 2, 7
- ];
- const gets = this.gets || getGets(test);
- const print = this.print || console.log;
- // code
- const n = +gets();
- const k = +gets();
- const arr = new Array();
- for(let i = 0; i < n; i++) {
- arr.push(gets());
- }
- var sortedArr = arr.sort().reverse();
- //print(sortedArr);
- var sum = 0;
- for(let n =0; n<k; n++) {
- sum += sortedArr[n];
- }
- print(sum);
Advertisement
Add Comment
Please, Sign In to add comment