#include #include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); uint16_t N, K, i; cin >> N >> K; vector a(N); for (i = 0; i != N; ++i) cin >> a[i]; sort(a.begin(), a.end(), greater()); vector gap(N - 1); for (i = 1; i != N; ++i) gap[i - 1] = a[i - 1] - a[i]; sort(gap.begin(), gap.end(), greater()); uint64_t gap_sum = 0; for (i = 0; i != K - 1; ++i) gap_sum += gap[i]; cout << a[0] - a[N - 1] - gap_sum << '\n'; return 0; }