Submission #1088466

# Submission time Handle Problem Language Result Execution time Memory
1088466 2024-09-14T12:56:54 Z Roupiq Stove (JOI18_stove) C++17
100 / 100
18 ms 2004 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define x first
#define y second
using pii = pair<int, int>;
template <typename T1, typename T2>
ostream &operator<<(ostream &_o, pair<T1, T2> _a)
{
    _o << _a.x << " " << _a.y;
    return _o;
}

int n, k;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    
    priority_queue<int> dif;
    int last;
    cin >> last;
    last++;
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a;
        b = a + 1;
        dif.push(-(a - last));
        last = b;
    }

    int res = 0;
    while(len(dif) > k - 1)
    {
        res += -dif.top();
        dif.pop();
    }

    cout << res + n << "\n";
}

/*
3 2
1
3
6

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 17 ms 1760 KB Output is correct
17 Correct 17 ms 1760 KB Output is correct
18 Correct 18 ms 1992 KB Output is correct
19 Correct 17 ms 1760 KB Output is correct
20 Correct 14 ms 1880 KB Output is correct
21 Correct 11 ms 1908 KB Output is correct
22 Correct 9 ms 2004 KB Output is correct
23 Correct 9 ms 1760 KB Output is correct
24 Correct 8 ms 1760 KB Output is correct