#pragma GCC optimize("O3") #pragma GCC target("avx") #include // #include #include using namespace std; // #define int long long #define REP(i, n) for (int i = 0; i < (n); i++) #define ALL(a) begin(a), end(a) #define let const auto int scan() { int result = 0; while (true) { auto k = getchar_unlocked(); if (k < '0' || k > '9') break; else result = 10 * result + k - '0'; } return result; } // let n = scan() // let k = scan() // let A = newSeqWith(n,scan()).sorted(cmp) // let B = A.getNeignborDiff().sorted(cmp) // echo B[0..<(n-k)].sum() int main() { let n = scan(); let k = scan(); vector A(n); REP(i, n) A[i] = scan(); sort(ALL(A)); vector B(n - 1); REP(i, n - 1) B[i] = A[i + 1] - A[i]; sort(ALL(B)); int ans = 0; REP(i, n - k) ans += B[i]; printf("%d\n", ans); }