func_code_string: #include <bits/stdc++.h>   using namespace std;   int a[300005];   int l[5005], r[5005];   long long dp[5005][5005];   const long long inf = 2e16;   void Min(long long &a, long long b) {     if (a > b) a = b;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int cur = 0, tmp = n / k;     int c1 = n - tmp * k, c2 = k - c1;     for (int i = 0; i < 5005; i++)       for (int j = 0; j < 5005; j++) dp[i][j] = inf;     for (int i = 1; i <= k; i++) {       if (c1 < i)         r[i] = min(n, c1 * (tmp + 1) + (i - c1) * tmp);       else         r[i] = min(n, i * (tmp + 1));       if (c2 < i)         l[i] = min(n, c2 * tmp + (i - c2) * (tmp + 1));       else         l[i] = min(n, i * tmp);     }     dp[0][0] = 0;     for (int i = 1; i <= k; i++)       for (int j = l[i]; j <= r[i]; j++) {         int pre = j - tmp;         if (pre <= r[i - 1] && pre >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - l[i - 1]] + a[j] - a[pre + 1]);         if (pre - 1 <= r[i - 1] && pre - 1 >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - 1 - l[i - 1]] + a[j] - a[pre]);       }     printf( %d n , dp[k][n - l[k]]);     return 0;   }   