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;
typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FR(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define RF(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
int main() {
int N, K;
cin >> N >> K;
vector<int> split;
int last;
cin >> last;
int first = last;
FR(i, N-1) {
int next;
cin >> next;
if (next - last > 1) {
split.push_back(next-(last+1));
}
last = next;
}
int rem = 0;
sort(split.begin(), split.end());
for (int k = 1; k <= min(K-1, int(split.size())); k++) {
rem += split[split.size()-k];
}
cout << (last + 1 - first - rem);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |