제출 #1347689

#제출 시각아이디문제언어결과실행 시간메모리
1347689Yusif_NazarliStove (JOI18_stove)C++20
큐에 대기중
0 ms0 KiB
#include "bits/stdc++.h"

#define int unsigned long long
#define all(v) v.begin() , v.end()
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int , int>
#define pb push_back
#define F first
#define S second
using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;


void Yusiff(){
  int n , k; cin >> n >> k;
  int a[n + 1];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  if(n <= k){
    cout << n << '\n';
  }
  vector<array<int , 3>> arr;
  for(int i = 1; i < n; i++){
    int diff = a[i] - a[i - 1];
    arr.pb({diff , i - 1 , i});
  }
  sort(all(arr));
  int m = n - k;
  int sum = k;
  for(int i = 0; i < m; i++){
    sum += arr[i][0];
  }
  cout << sum << '\n';
}


signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // freopen("wormsort.in", "r", stdin);
  // freopen("wormsort.out", "w", stdout);

  int T = 1;
  // cin >> T;
  while(T--){
    Yusiff();
  }
}

/*


*/