题目描述
Problem Description
There are $ N $ jewels numbered from $ 1 $ to $ N $. The color of jewel $ i $ is $ C_i $ and its value is $ V_i $. Here, the color is represented by an integer between $ 1 $ and $ N $ inclusive.
A pair of jewels $ (i,j) $ is called a good pair if and only if both of the following conditions are satisfied:
- $C_i \neq C_j$
- $V_i + V_j \leq L$
You are trying to create some good pairs from the $ N $ jewels. A jewel cannot be included in more than one pair, but it is allowed to not be included in any pair.
Find the maximum possible total value of the jewels included in the created pairs.
Input Format
The input is given from the standard input in the following format:
$ N $ $ L $ $ C_1 $ $ V_1 $ $ C_2 $ $ V_2 $ $\vdots$ $ C_N $ $ V_N $
Output Format
Output the answer.
Sample Input and Output
Sample Input #1
4 5
1 2
1 3
2 1
2 4
Sample Output #1
4
Sample Input #2
5 10
3 8
4 2
1 5
1 3
1 2
Sample Output #2
17
Sample Input #3
9 10
8 2
7 10
1 4
3 0
5 3
3 6
2 5
5 9
5 4
Sample Output #3
34
Sample Input #4
20 1000000000
15 239276621
15 910500852
15 245532750
15 715892722
16 80707349
15 257261830
12 950300098
15 322288793
15 256358887
15 504976376
2 907119713
15 152036484
13 298766520
15 480968804
15 285187325
13 755031424
15 69837029
15 88860861
9 596982638
15 272961035
Sample Output #4
4704511147
Notes/Hints
Constraints
- $1 \leq N \leq 250000$
- $1 \leq L \leq 10^9$
- $1 \leq C_i \leq N$
- $0 \leq V_i \leq L$
- All values inputted are integers.
Sample Explanation 1
The pair $ (1,2) $ does not satisfy the first condition, so it is not a good pair. The pair $ (1,4) $ does not satisfy the second condition, so it is not a good pair. The optimal way to form pairs in this input example is to form the pair $ (2,3) $.
Sample Explanation 2
The optimal way to form pairs in this input example is to form the pairs $ (1,5),(2,3) $.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分