Party
Time limit2sMemory limit1024 MB
Pair up girls with different personality types so each pair's happiness sum is at most k, maximizing the total happiness of all paired girls.
- Level
Medium7 of 10
- Topics
- Sorting, Two pointers, Greedy
- Solved
- No attempts yet
Problem
cherry blossom girls held a party. At this party, they will form dating relationships. A dating relationship is formed between two cherry blossom girls, and each girl can belong to at most one dating relationship.
Each girl has a personality type and a happiness value . For two girls and to form a dating relationship, their personality types must be different (), and the sum of their happiness values must be at most (). is an integer given as input.
Find the maximum possible sum of happiness values of the girls who are in dating relationships.
Input
The first line contains two integers and .
Each of the next lines contains two integers and , the personality type and happiness value of the -th girl.
Output
Print one integer, the maximum possible sum of happiness values of the girls in dating relationships.