#include #define rep(i,a,b) for(int i=int(a);i> N >> M; vector V(N),dif(N-1); rep(i,0,N)cin >> V[i]; sort(V.begin(), V.end()); ll sum = V.back() - V.front(); rep(i,0,N-1)dif[i] = V[i+1] - V[i]; sort(dif.rbegin(), dif.rend()); rep(i,0,M-1)sum -= dif[i]; cout << sum << endl; }