제출 #330371

#제출 시각아이디문제언어결과실행 시간메모리
330371casperwangStove (JOI18_stove)C++14
100 / 100
29 ms2048 KiB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int MAXN = 100000;
int n, k;
int a[MAXN];
int d[MAXN];
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a+n);
  for (int i = 0; i+1 < n; i++)
    d[i] = a[i+1] - a[i] - 1;
  sort(d, d+n-1, greater<int>());
  ans = a[n-1] - a[0] + 1;
  for (int i = 0; i < k-1; i++)
    ans -= d[i];
  cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...