#P10336. [UESTCPC 2024] 2-聚类算法

[UESTCPC 2024] 2-聚类算法

Problem Description

Alice and Bob are two creatures in a kk-dimensional space. In the space they live in, there are 2n2n feature points. The coordinates of the ii-th feature point are (xi,1,xi,2,,xi,k)(x_{i,1}, x_{i,2}, \ldots, x_{i,k}).

In this space, the distance between two points is defined as the Manhattan distance between them (that is, the distance between point ii and point jj is disti,j=p=1kxi,pxj,p\text{dist}_{i,j}=\sum_{p=1}^{k}|x_{i,p}-x_{j,p}|).

Alice and Bob need to collect these feature points. They take turns choosing one point from these 2n2n points, and a point that has already been chosen cannot be chosen again. Alice moves first. Alice puts the points she chooses into set S1S_1, and Bob puts the points he chooses into set S2S_2.

Define the value of a set val(S)\text{val}(S) as the sum of distances between every pair of points in it. Alice wants to maximize val(S1)val(S2)\text{val}(S_1)-\text{val}(S_2), while Bob wants to minimize val(S1)val(S2)\text{val}(S_1)-\text{val}(S_2).

If both Alice and Bob use optimal strategies, find the final value of val(S1)val(S2)\text{val}(S_1)-\text{val}(S_2).

Input Format

The first line contains two integers n,kn,k (1n,k105,n×k105)(1\leq n,k\leq 10^5, n\times k\leq 10^5), representing half the number of feature points and the number of dimensions in the space.

The next 2n2n lines each contain kk integers xi,1,xi,2,,xi,kx_{i,1}, x_{i,2}, \ldots, x_{i,k} (108xi,j108)(-10^8\leq x_{i,j}\leq 10^8), representing the coordinates of the ii-th feature point.

Output Format

Output one integer, representing the value of val(S1)val(S2)\text{val}(S_1)-\text{val}(S_2) when both Alice and Bob use optimal strategies.

“The sum of distances between every pair of points” counts each unordered pair only once.

2 2
1 0
0 1
1 1
0 0
0

Hint

Translated by ChatGPT 5