Party Medley
InterviewTime limit1sMemory limit2048 MB
Count the teams of three distinct students whose max minus min rating is at most M, and find the largest rating sum among those teams.
- Level
Medium4 of 10
- Topics
- Brute force, Sorting, Combinatorics
- Solved
- No attempts yet
Problem
ICPC University has students, numbered from to , in its Competitive Programming club. Student has a rating of , which estimates their skill in competitive problem-solving.
Contest season is coming, and Morgan, the coach of the club, wants to send at most one good team to a particular contest because the budget is limited. A team consists of exactly different students. If a team consists of students , , and , then their team rating is , and their rating difference is .
Morgan considers a team balanced if its rating difference is at most a threshold . Among balanced teams, Morgan wants the team rating to be as large as possible.
Morgan asks for two values. The first is the number of balanced teams that can be formed. The second is the largest team rating of a balanced team that can be formed. Two team configurations are different if at least one student differs between them.
Input
The first line contains two integers and (; ). The next line contains integers (), the rating of student .
Output
If at least one balanced team configuration exists, print two space-separated integers on one line: the number of balanced team configurations, and the largest team rating of any balanced team. If no balanced team configuration exists, print -1 on one line.