Submission #587589

# Submission time Handle Problem Language Result Execution time Memory
587589 2022-07-02T06:28:28 Z dryeab Stove (JOI18_stove) C++17
100 / 100
59 ms 1960 KB
#include <bits/stdc++.h>

using namespace std;

const int M = 1e5 + 5;

int t[M];
int gap[M];

int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0);

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
        cin >> t[i];

    int res = n;

    if (k >= n)
    {
        cout << res << endl;
        return 0;
    }

    sort(t, t + n);
    for (int i = 1; i < n; ++i)
        gap[i - 1] = -(t[i] - t[i - 1] - 1);

    sort(gap, gap + n - 1);

    k--;
    for (int i = k; i < n - 1; ++i)
        res += -gap[i];

    cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 352 KB Output is correct
16 Correct 44 ms 1956 KB Output is correct
17 Correct 44 ms 1848 KB Output is correct
18 Correct 43 ms 1308 KB Output is correct
19 Correct 44 ms 1960 KB Output is correct
20 Correct 45 ms 1068 KB Output is correct
21 Correct 59 ms 1872 KB Output is correct
22 Correct 44 ms 1880 KB Output is correct
23 Correct 45 ms 1128 KB Output is correct
24 Correct 43 ms 972 KB Output is correct