제출 #1316416

#제출 시각아이디문제언어결과실행 시간메모리
1316416wasbaldStove (JOI18_stove)C++20
100 / 100
38 ms2328 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define sc second
const int mod = 1e+9;
int dp[1000000];
queue<int>q; 
map<int,int>mp;        
signed main(){
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    for(int i = 0; i < n; i++){
        cin >>a[i];
    }
    if(n <= k)cout << n << endl;
    else{   
    int bruh = 0;
    vector<int>v;
    for(int i = 0; i < n - 1; i++){
        v.pb((a[i+1] - a[i]) - 1);
    }
    sort(v.rbegin(), v.rend());
    for(int i = 0; i < k - 1; i++) {
        bruh += v[i];
    }
    cout << (a[n-1] - a[0] + 1) - bruh << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...