답안 #970513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970513 2024-04-26T16:15:20 Z shezitt Stove (JOI18_stove) C++14
100 / 100
21 ms 3548 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){
        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;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 516 KB Output is correct
16 Correct 21 ms 3292 KB Output is correct
17 Correct 21 ms 3292 KB Output is correct
18 Correct 21 ms 3548 KB Output is correct
19 Correct 20 ms 3292 KB Output is correct
20 Correct 18 ms 3288 KB Output is correct
21 Correct 12 ms 3180 KB Output is correct
22 Correct 11 ms 3292 KB Output is correct
23 Correct 13 ms 3292 KB Output is correct
24 Correct 12 ms 3292 KB Output is correct