Submission #679362

# Submission time Handle Problem Language Result Execution time Memory
679362 2023-01-08T07:14:35 Z vjudge1 Stove (JOI18_stove) C++14
100 / 100
25 ms 6852 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i --)

using namespace std;
const long long N = 1e5 + 5;

ll n, a[N], k;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];

    vector <pii> vi;
    vector <pii> pos;
    vi.push_back({a[1], a[1] + 1});

    ll ans = 0;

    rep(i, 2, n) {
        if (a[i] == vi.back().nd) {
            vi.back().nd ++;
            continue;
        }

        vi.push_back({a[i], a[i] + 1});
    }

    int cnt = 0;
    for (pii x: vi) {
        ans += x.nd - x.st;
        cnt ++;
    }

    rep(i, 1, (int)vi.size() - 1)
        pos.push_back({vi[i].st - vi[i - 1].nd, i});

    sort(pos.begin(), pos.end());

    int j = 0;
    while (cnt > k) {
        ans += pos[j].st;
        j ++;
        cnt --;
    }

    cout << ans;

    return 0;
}




# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 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 336 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 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 328 KB Output is correct
3 Correct 0 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 336 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 1 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 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 336 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 1 ms 496 KB Output is correct
16 Correct 23 ms 6700 KB Output is correct
17 Correct 25 ms 6700 KB Output is correct
18 Correct 25 ms 6660 KB Output is correct
19 Correct 25 ms 6732 KB Output is correct
20 Correct 24 ms 6852 KB Output is correct
21 Correct 23 ms 6600 KB Output is correct
22 Correct 23 ms 6716 KB Output is correct
23 Correct 24 ms 6612 KB Output is correct
24 Correct 23 ms 6732 KB Output is correct