Team Formation
Time limit1sMemory limit1024 MB
Given N members with skill and target rank, pick disjoint triples whose rank spread is at most K to maximize the total skill of the chosen triples.
- Level
Medium6 of 10
- Topics
- Sorting, Dynamic programming, Sliding window
- Solved
- No attempts yet
Problem
DoHun posted a notice to encourage DPS members to join ICPC and wants to group the members who do not have a team yet into teams of 3. There are members numbered 1 to . Member has programming skill and target rank .
To get the best results, DoHun forms teams that satisfy the following conditions.
- Each team must have exactly 3 members.
- A member cannot belong to more than one team.
- In a team, the difference between the highest target rank and the lowest target rank among its three members must be at most .
- Not every member has to be on a team.
The team skill of a team is the sum of the programming skills of its three members. DoHun wants the total team skill to be as large as possible. Find the maximum possible total team skill when the teams are formed under these conditions.
Input
The first line contains the number of members and , separated by a space. (, )
The next lines each contain the programming skill and the target rank of member , separated by a space. ()
Output
Print the maximum total team skill when the teams are formed under the conditions.