제출 #1242300

#제출 시각아이디문제언어결과실행 시간메모리
1242300vanhppStove (JOI18_stove)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pq priority_queue
using namespace std;

const ll MAXN = 100005;
ll n, k;
vector<pair<ll, ll>> pa;
vector<pair<ll, ll>> nw;
vector<pair<ll, ll>> inter() {
    nw.push_back(pa[0]);
    for (int i = 1; i < n; i++) {
        ll st = pa[i].fi;
        ll ed = pa[i].se;
        ll lst = nw.back().fi;
        ll led = nw.back().se;
        if (st <= led) {
            led = max(led, ed);
        } else {
            nw.push_back({st, ed});
        }
    }

    return nw;
}

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        pa.push_back({x, x + 1});
    }
    sort(pa.begin(), pa.end());
    inter();
    ll m = nw.size();
    if (m <= k){
        ll tong = 0 ;
        for (auto x : nw){
            tong += abs(x.fi - x.se) ;
        }
        cout << tong ;
        return 0 ;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...