Submission #715864

# Submission time Handle Problem Language Result Execution time Memory
715864 2023-03-28T08:44:53 Z TheSahib Stove (JOI18_stove) C++17
100 / 100
50 ms 1796 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 1e5 + 5;

int n, k;
int arr[MAX];

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    vector<int> ranges;

    for (int i = 0; i < n - 1; i++)
    {
        ranges.emplace_back(arr[i + 1] - arr[i] - 1);
    }
    int ans = arr[n - 1] - arr[0] + 1;
    sort(ranges.begin(), ranges.end());
    reverse(ranges.begin(), ranges.end());
    for (int i = 0; i < k - 1; i++)
    {
        ans -= ranges[i];
    }
    
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 304 KB Output is correct
7 Correct 1 ms 308 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 1 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 304 KB Output is correct
7 Correct 1 ms 308 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 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 316 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 304 KB Output is correct
7 Correct 1 ms 308 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 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 316 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 45 ms 1740 KB Output is correct
17 Correct 46 ms 1780 KB Output is correct
18 Correct 47 ms 1760 KB Output is correct
19 Correct 46 ms 1736 KB Output is correct
20 Correct 45 ms 1796 KB Output is correct
21 Correct 46 ms 1768 KB Output is correct
22 Correct 46 ms 1784 KB Output is correct
23 Correct 48 ms 1796 KB Output is correct
24 Correct 50 ms 1720 KB Output is correct