답안 #304609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304609 2020-09-21T15:16:42 Z vishesh312 Stove (JOI18_stove) C++17
100 / 100
28 ms 2432 KB
#include <bits/stdc++.h>
using namespace std;

#define deb(x)        cerr << #x << " = " << x << "\n";
#define deb2(x, y)    cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";

#define pb push_back
#define mp make_pair
#define F  first
#define S  second

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;  

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> ent(n);
    for (int i = 0; i < n; ++i) {
        cin >> ent[i];
    }
    priority_queue<int> pq;
    sort(all(ent));
    for (int i = 0; i < n-1; ++i) {
        pq.push(ent[i+1] - ent[i] - 1);
    }
    int a = 0;
    for (int i = 0; i < k-1 && !pq.empty(); ++i) {
        a+= pq.top();
        pq.pop();
    }
    cout << (ent[n-1] - ent[0] - a + 1);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    ll tc = 1;
    //cin >> tc;

    while(tc--) {
        solve();
        cout << '\n';
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 2296 KB Output is correct
17 Correct 16 ms 2304 KB Output is correct
18 Correct 17 ms 2304 KB Output is correct
19 Correct 17 ms 2432 KB Output is correct
20 Correct 22 ms 2304 KB Output is correct
21 Correct 28 ms 2304 KB Output is correct
22 Correct 28 ms 2304 KB Output is correct
23 Correct 28 ms 2304 KB Output is correct
24 Correct 28 ms 2304 KB Output is correct