0

# HAcker earth Problem

Guys please me correction in my code for given problem :- https://www.hackerearth.com/practice/data-structures/arrays/1-d/practice-problems/algorithm/maximize-sum-0423b95e/ my code :- from collections import Counter T=int(input()) for _ in range(0,T): N,K =map(int,input().split()) A=list(map(int,input().split())) A = Counter(A) s1=[] key=list(A.keys()) for i in range(0,len(key)): s1.append( (key[i]) * (A.get(key[i])) ) s1.sort() sum=0 for j in s1[-K:]: sum=sum+j print(sum) this is my code out of 16 test case I have pass only 8 test cases by using this code please tell me correction in my code for pass all 16 test cases

1 Answer

+ 1

For me it works well , but i don't see any option there to run the code in python or i would have tested it myself. Maybe try checking for constraints as well.