Submission #970510

# Submission time Handle Problem Language Result Execution time Memory
970510 2024-04-26T16:12:49 Z shezitt Stove (JOI18_stove) C++14
0 / 100
0 ms 600 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <queue>

using namespace std;

using ll = long long;

#define int ll
#define fore(a, b, c) for(int a=b; a<c; ++a)
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define ii pair<int,int>
#define F first
#define S second

const int MAXN = 1e5+5;

int n, k;
int a[MAXN];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> k;

    fore(i, 0, n){
        cin >> a[i];
    }

    if(n <= k){
        cout << n;
        return 0;
    }

    priority_queue<int, vector<int>, greater<int>> st;
    sort(a, a+n);

    int ans = n;
    fore(i, 1, n){
        if(a[i-1] + 1 == a[i]) continue;
        st.push(a[i] - a[i-1] - 1);
    }

    int cnt = sz(st) + 1;

    if(cnt <= k){
        cout << cnt;
        return 0;
    }

    int rem = cnt - k;

    while(rem--){
        assert(sz(st) > 0);
        ans += st.top();
        st.pop();
    }

    cout << ans;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -