#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long #define rep(i,s,n) for(int i = s;i=(s);i--) #define all(v) (v).begin(),(v).end() #define pb push_back #define fi first #define se second #define chmin(a,b) a=min((a),(b)) #define chmax(a,b) a=max((a),(b)) #define l1 list[index] #define l2 list[index - 1] #define l3 list[index + 1] #define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false typedef long long ll; typedef pairpint; typedef vectorvint; typedef vectorvpint; typedef pair P1; typedef pair P2; typedef pair PP; static const ll maxLL = (ll)1 << 62; const ll MOD = 1000000007; const ll INF = 1e18; const double PI = 3.14159265359; int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; signed main() { string s; //vector>list(200000, vector(2)); vectorlistsum; vector>list, list2; int l, cnt = 0, maxn = 0; int n, n2, k, sum = 0, sumsum = 0; cin >> n >> k; listsum.push_back(0); for (int i = 0; i < n; i++) { int num; cin >> num; //list.push_back(num); list.push_back(make_pair( num, i)); //sumsum += num; } //cout << endl; sort(list.begin(), list.end()); sumsum = list[list.size() - 1].first - list[0].first; for (int i = 1; i < n; i++) { int num = list[i].first - list[i - 1].first; list2.push_back( make_pair(num, i - 1)); //list2.push_back(num); listsum.push_back(listsum[listsum.size() - 1] + list[i].first); } sort(list2.begin(), list2.end()); vectorlist4; for (int i = 0; i < k-1; i++) { //list4.push_back(list2[list2.size() - i - 1].second); sumsum -= list2[list2.size() - i - 1].first; } //cout << "sumsum->" << sumsum << endl; cout << sumsum << endl; //sort(list4.begin(), list4.end()); //int index = 0; //for (int i = 0; i < (int)list4.size(); i++) { // //sum += listsum[list4[i]] - listsum[index]; // sum += list[list4[i]].first - list[index].first; // index = list4[i] + 1; //} //cout << "sum->" << sum << endl; //for (int i = 0; i < n; i++) { // cout << list[i].first << " "; //} //cout << endl; //for (int i = 0; i < (int)list2.size(); i++) { // cout << list2[i].first << " "; //} //cout << endl; getchar(); getchar(); return 0; }