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 <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PF push_front
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll int INF = 1e18;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
// ifstream cin();
// ofstream cout();
int n, k;
cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<int> itvl; // interval
for(int i = 1; i < n; i++){
itvl.PB(a[i] - a[i-1] - 1);
}
sort(itvl.rbegin(), itvl.rend());
ll int tot = a[n-1] - a[0] + 1, rest = 0;
for(int i = 0; i < k-1; i++) rest += itvl[i];
cout << tot-rest << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |