Group Meetings (APCS 2025-01 Expert)
2.0s 256MThere are \(n\) people at positions \(x_i\) on a line. Choose two disjoint groups of \(k\) people each. Each group chooses a meeting point; its members pay their distances to it. Minimize the total distance.
Input Format
Read \(n,k\), then the \(n\) positions.
Output Format
Print the minimum total distance.
Constraints
\(1\le k\), \(2k\le n\le200000\); \(0\le x_i\le10^9\). Positions may repeat.
Scoring
- 30 points: \(n\le100\).
- 70 points: No additional restrictions.
Each scored test is worth 5 points.
Sample Input 1
6 2
5 2 0 6 9 6
Sample Output 1
2
Sample Input 2
7 3
6 3 2 2 0 9 8
Sample Output 2
4
Source
APCS 2025-01 public archive version: q184。
Log in to write and submit code.
Log in