제출 #1283068

#제출 시각아이디문제언어결과실행 시간메모리
1283068lechaaStove (JOI18_stove)C++20
100 / 100
15 ms2244 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k; cin >> n >> k;
  vector<int> t(n);
  for(int i = 0; i < n; i++){
    cin >> t[i];
  }
  int cur = t.back() - t[0] + 1;
  vector<int> d;
  for(int i = 0; i < n-1; i++){
    d.push_back(t[i+1] - t[i] - 1);
  }
  sort(d.rbegin(), d.rend());
  int sz = d.size();
  for(int i = 0; i < min(k-1, sz); i++){
    cur -= d[i];
  }
  cout << cur << "\n";
  return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...