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 forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO {ios::sync_with_stdio(0); cin.tie(NULL);}
typedef long long tint;
const int INF = 50000200;
const int MOD = 1e9+7;
const int N = 100001;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
bool valid(int x, int y, int n, int m){ return (0<=x && x<n && 0<=y && y<m);}
int main(){
NACHO;
int n, k;
cin >> n >> k;
vector<int> t (n);
forn(i, n) cin >> t[i];
vector<int> difs;
forsn(i, 1, n) difs.push_back(t[i]-t[i-1]-1);
sort(rall(difs));
int tot = t.back()-t[0]+1;
forn(i, k-1){
tot-=difs[i];
}
cout << tot << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |