답안 #659319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659319 2022-11-17T13:07:34 Z illyakr Stove (JOI18_stove) C++14
100 / 100
44 ms 3196 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long

using namespace std;

int n, k;
int t[101010];
int res = 0;
vector<int> dif;
int32_t main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    for (int i = 2; i <= n; i++) {
        dif.push_back(t[i] - t[i - 1]);
    }
    res = t[n] - t[1] + 1;
    sort(dif.begin(), dif.end(), greater<int>());
    for (int i = 0; i + 1 < k; i++) {
        res -= dif[i];
        res++;
    }
    cout << res;
}

/**
3 2
1
3
6

3 1
1
3
6

10 5
1
2
5
6
8
11
13
15
16
20
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 316 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 316 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 44 ms 3140 KB Output is correct
17 Correct 42 ms 3188 KB Output is correct
18 Correct 42 ms 3188 KB Output is correct
19 Correct 42 ms 3116 KB Output is correct
20 Correct 42 ms 3144 KB Output is correct
21 Correct 44 ms 3196 KB Output is correct
22 Correct 42 ms 3100 KB Output is correct
23 Correct 44 ms 3104 KB Output is correct
24 Correct 43 ms 3116 KB Output is correct