atcoder#AGC034D. [AGC034D] Manhattan Max Matching
[AGC034D] Manhattan Max Matching
Score : points
Problem Statement
Snuke is playing with red and blue balls, placing them on a two-dimensional plane.
First, he performed operations to place red balls. In the -th of these operations, he placed red balls at coordinates . Then, he performed another operations to place blue balls. In the -th of these operations, he placed blue balls at coordinates . The total number of red balls placed and the total number of blue balls placed are equal, that is, . Let this value be .
Snuke will now form pairs of red and blue balls so that every ball belongs to exactly one pair. Let us define the score of a pair of a red ball at coordinates and a blue ball at coordinates as .
Snuke wants to maximize the sum of the scores of the pairs. Help him by finding the maximum possible sum of the scores of the pairs.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible sum of the scores of the pairs.
2
0 0 1
3 2 1
2 2 1
5 0 1
8
If we pair the red ball at coordinates and the blue ball at coordinates , the score of this pair is . Then, if we pair the red ball at coordinates and the blue ball at coordinates , the score of this pair is . Making these two pairs results in the total score of , which is the maximum result.
3
0 0 1
2 2 1
0 0 2
1 1 1
1 1 1
3 3 2
16
Snuke may have performed multiple operations at the same coordinates.
10
582463373 690528069 8
621230322 318051944 4
356524296 974059503 6
372751381 111542460 9
392867214 581476334 6
606955458 513028121 5
882201596 791660614 9
250465517 91918758 3
618624774 406956634 6
426294747 736401096 5
974896051 888765942 5
726682138 336960821 3
715144179 82444709 6
599055841 501257806 6
390484433 962747856 4
912334580 219343832 8
570458984 648862300 6
638017635 572157978 10
435958984 585073520 7
445612658 234265014 6
45152033546