This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define inf int(2e9)
#define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,k;
ll niz[300005];
vector<ll>val;
ll res;
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> k;
ff(i,0,n - 1){
cin >> niz[i];
}
sort(niz, niz + n);
ff(i,0,n-2){
val.pb(niz[i] - niz[i + 1]);
//cout << niz[i] - niz[i+1] << endl;
}
int tmpk = k;
sort(val.begin(), val.end());
for(auto c:val){
if(k==1)break;
res += c;
k--;
if(k == 1)break;
}
res += niz[n-1];
res -= niz[0];
cout << res + tmpk;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |