N number of people participated in a coding marathon where they were asked to solve some problems. Each problem carried 1 mark and at the end of the marathon, the total marks that each person achieved was calculated. As an organizer, you have the list of the total marks that each person achieved. You have to calculate the sum of the marks of top K scorers from the list. Input Specification: input1: N, Total number of participants input2: Top scorers input3: An array of length N with the scores of all N participants Output Specification: Return S, sum of the marks of top K scorers from the list. Example 1: input1: 4 input2: 2 input3: {4, 1, 2, 5} Output: 9 Explanation: Top 2 scores are 5 and 4. Sum = 5+4=9. Example 2: input1: 4 input2: 3 input3: {4, 3, 6, 1} Output: 13 Explanation: Top 3 scores are 6, 4 and 3. Sum = 6+4+3=13.
Answers
Coding Marathon Program
Language used: Python Programming
Program: For execution, check the attachments given beow
n=int(input()) #total number of participants
t=int(input()) #Top scorers input
l=list(map(int,input().split(' '))) #List of all the scores
l=sorted(l)[::-1] #Arranging scores in descending order - large to small
print(sum(l[:t])) #Summing up the 't' top scores and printing the total
Input 1:
4
2
4 1 2 5
Output 1:
9
Input 2:
4
3
4 3 6 1
Output 2:
13
Learn more:
1. What is list comprehension python?
brainly.in/question/6964716
2. Ch+=2 is equivalent to
https://brainly.in/question/21331324
Answer:
It's Very Easy
Explanation:
n = int(input())
k = int(input())
sum = 0
arr = list(map(int, input().split(' ')))
arr.sort(reverse= True)
for i in range(0,k):
sum = sum+arr[i]
print(sum)