답안 #906106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906106 2024-01-13T14:01:57 Z JCC Stove (JOI18_stove) C++14
100 / 100
43 ms 2384 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int solve(int K, vector<int> & arrivals) {
    int N = (int) arrivals.size();
    vector<int> gapSizes(N-1);
    for (int i = 0; i < N-1; i++)
        gapSizes[i] = arrivals[i+1]-arrivals[i]-1;

    sort(gapSizes.begin(), gapSizes.end(), greater<int>());

    int answer = arrivals[N-1]+1 - arrivals[0];
    for (int i = 0; i < K-1; i++) {
        answer -= gapSizes[i];
    }
    return answer;
}

int main() {

    int N, K;
    vector<int> arrivals;
    cin >> N >> K;
    arrivals = vector<int>(N);
    for (int i = 0; i < N; i++)
        cin >> arrivals[i];
    cout << solve(K, arrivals) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 520 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 520 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 34 ms 2104 KB Output is correct
17 Correct 36 ms 2140 KB Output is correct
18 Correct 43 ms 2384 KB Output is correct
19 Correct 34 ms 2132 KB Output is correct
20 Correct 36 ms 2132 KB Output is correct
21 Correct 35 ms 2092 KB Output is correct
22 Correct 36 ms 1964 KB Output is correct
23 Correct 34 ms 2132 KB Output is correct
24 Correct 34 ms 2048 KB Output is correct