#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define Would #define you const int INF = 999999999; const int MOD = 1e9 + 7; const double pi = 3.141592653589793238; int main() { int a, b; long long k[50005], l[50005], ans = 0; cin >> a >> b; for (int i = 0; i < a; ++i) { cin >> k[i]; } sort(k, k + a); l[0] = k[0]; for (int i = 1; i < a; ++i) { l[i] = k[i] - k[i - 1]; } sort(l, l + a); for (int i = 0; i <= b; ++i) { ans += l[i]; } cout << ans << endl; }