inlinevoidmain(){ read(n), read(k); for (int i = 1, x; i <= n; ++i) read(x), a[x+L]++; for (int i = 0; i <= L+L; ++i) f[0] += a[i] * i; // l,r 分别是该位置左右两边的点数 r = n; for (int i = 1; i <= L+L; ++i) { l += a[i-1]; f[i] = f[i-1] + l - r; r -= a[i]; } sort(f, f+L+L+1); for (int i = 0; i < k; ++i) ans += f[i]; printf("%lld\n", ans); return0; }