답안 #532357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532357 2022-03-02T18:28:50 Z sep Stove (JOI18_stove) C++14
100 / 100
50 ms 2024 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 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 304 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 304 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 50 ms 1948 KB Output is correct
17 Correct 44 ms 1964 KB Output is correct
18 Correct 46 ms 1936 KB Output is correct
19 Correct 45 ms 2024 KB Output is correct
20 Correct 45 ms 1960 KB Output is correct
21 Correct 46 ms 1944 KB Output is correct
22 Correct 47 ms 1944 KB Output is correct
23 Correct 45 ms 1948 KB Output is correct
24 Correct 48 ms 1988 KB Output is correct