제출 #1288218

#제출 시각아이디문제언어결과실행 시간메모리
1288218tit_manhStove (JOI18_stove)C++20
100 / 100
18 ms1320 KiB
/*
    author : TIT_manh
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <numeric> 
#include <functional>
#include <cassert>
#include <sstream>
#include <climits> 
#define ll long long
#define FOR(i,l,r) for (int i = l; i <= r; i++)
#define FOD(i,r,l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 5;
int n, k, a[maxn];
priority_queue<int> pq;
void I_love() {
    cin >> n >> k;
    FOR(i,1,n) {
        cin >> a[i];
        if (i != 1) pq.push(a[i] - a[i - 1] - 1);
    }
}
void tvka() {
    ll res = a[n] - a[1] + 1, tmp = 1;
    while (tmp < k) {
        tmp++;
        res -= pq.top();
        pq.pop();
    }
    cout << res;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    I_love(); tvka();
    return 0; 
}
/*
████████╗ ██╗   ██╗ ██╗  ██╗  █████╗ 
╚══██╔══╝ ██║   ██║ ██║ ██╔╝ ██╔══██╗
   ██║    ██║   ██║ █████╔╝  ███████║
   ██║    ██║  ██║  ██╔═██╗  ██╔══██║
   ██║     ╚██╔╝    ██║  ██╗ ██║  ██║
   ╚═╝     ╚══╝     ╚═╝  ╚═╝ ╚═╝  ╚═╝

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