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>
using namespace std;
#define iloop(x, n) for (long long i = x; i < n; ++i)
#define jloop(x, n) for (long long j = x; j < n; ++j)
#define kloop(x, n) for (long long k = x; k < n; ++k)
#define dloop(x, n) for (long long d = x; d >= n; --d)
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int, int>
#define iii tuple<int, int, int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define int long long
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define dg(x) cout << #x << ": " << x << endl
#define all(x) x.begin(), x.end()
#define flag cout << "HERE" << endl;
#define FASTIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define prt(x) \
cout << "Vector " << #x << endl << ":"; \
for (auto it : x) cout << it << " "; \
cout << endl;
#define ppr(x) \
cout << "Pair " << #x << endl << ":";\
cout << x.first << " " << x.second << endl;
int32_t main(){
FASTIO
int n, k; cin >> n >> k;
vector<int> v(n);
iloop(0, n){
cin >> v[i];
}
sort(all(v));
vi diff;
iloop(0, n-1){
diff.pb(v[i+1] - v[i] - 1);
}
sort(all(diff));
int ans = n;
iloop(0, n - k){
ans += diff[i];
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |