Question: Code in C Language and explain the algorithm. Thank you Party Medley ICPC University has N students, numbered from 1 to N, in its Competitive
Code in C Language and explain the algorithm.
Thank you
Party Medley
ICPC University has N students, numbered from 1 to N, in its Competitive Programming club. Student i has a rating of Ri representing their estimated skill in competitive problem-solving. Contest season is coming and Morgan, the coach of the Competitive Programming club, would like to send at most one good team to a particular contest due to their limited budget. A team consists of exactly 3 different students. Suppose that a team consists of student i, j, and k. Their team rating is Ai + Aj + Ak, and their rating difference is max(Ai, Aj, Ak) - min(Ai, Aj, Ak). Morgan believes that a team is balanced if their rating difference is no more than a threshold of M. Additionally, he also would like the team rating to be as large as possible while being a balanced team as well. Morgan asks you to compute two values. The first value is the number of different balanced team configurations that can be made. The second value is the largest team rating of a balanced team that can be made. Two team configurations are different if and only if there is at least one different student between those team configurations.
Input
Input begins with two integers N M (3 N 200; 0 M 4000) representing the number of students and the threshold for rating difference, respectively. The next line contains N integers Ai (0 Ai 4000) representing the rating of student i
Output
Input begins with two integers N M (3 N 200; 0 M 4000) representing the number of students and the threshold for rating difference, respectively. The next line contains N integers Ai (0 Ai 4000) representing the rating of student i
Sample Input #1 5 150 1400 1425 1250 4000 1300
Sample Output #1 2 4125
An example of a balanced team configuration is the team consisting of student 1, 3, and 5. Their team rating is 1400 + 1250 + 1300 = 3950. Their rating difference is 1400 - 1250 = 150, which is no more than 150. The other balanced team configuration is the team consisting of students 1, 2, and 5. Their rating difference is 125 with a team rating of 4125, which is the highest team rating among all balanced team configurations
Sample Input #2 4 100 2000 1900 1800 2100
Sample Output #2 -1
Explanation for the sample input/output #2 Any team configuration has a rating difference of at least 200, which is more than the given threshold. that can be made.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
