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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 1000001;
const ll INF = (1LL << 59);
const ll MOD = 998244353;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
int v[NMAX];
vector <int> a;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int k, n, i;
cin >> n >> k;
k--;
for(i = 1; i <= n; i++){
cin >> v[i];
}
sort(v + 1, v + n + 1);
ll maxim = v[n] - v[1] + 1;
for(i = 2; i <= n; i++){
a.push_back(v[i] - v[i - 1] - 1);
}
sort(a.begin(), a.end());
while(a.size() && k--){
maxim -= a.back();
a.pop_back();
}
cout << maxim;
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... |