제출 #1347893

#제출 시각아이디문제언어결과실행 시간메모리
1347893BlockOGStove (JOI18_stove)C++20
100 / 100
12 ms1704 KiB
#include <bits/stdc++.h>

// mrrrowwww meeowwwww :3
// go play vivid/stasis! !! !!! https://vividstasis.gay

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = []{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    return 0;
}();

int t[100000];
bool off[100000];
pair<int, int> edges[99999];

int main() {
    int n, k; cin >> n >> k;
    fo(i, 0, n) cin >> t[i];
    fo(i, 1, n) off[i - 1] = true, edges[i - 1] = { t[i] - t[i - 1], i - 1 }; off[n - 1] = true;
    sort(edges, edges + n - 1);
    fo(i, 0, n - k) off[edges[i].s] = false;

    int res = 0;
    for (int i = 0, j = 0; i < n; i++)
        if (off[i]) res += t[i] + 1 - t[j], j = i + 1;
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...