답안 #707652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707652 2023-03-09T16:25:52 Z Urvuk3 Stove (JOI18_stove) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

#define EPS 1e-9
#define ll long long
const int INF=1e9,mxN=5001;
const ll LINF=1e18,MOD=1e9+7;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }
#define PRINTpair(x) cerr<<#x<<"={"<<x.fi<<","<<x.se<<"}"<<endl;

void Solve(){
    int N,K; cin>>N>>K;
    vector<ll> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    sort(all(a));
    vector<pll> comps;
    ll l=a[0];
    for(int i=1;i<N;i++){
        if(a[i]!=a[i-1]+1){
            comps.pb({l,a[i-1]+1});
            l=a[i];
        }
    } comps.pb({l,a[N-1]+1});
    ll res=0;
    for(auto p:comps) res+=p.se-p.fi;
    int off=sz(comps);
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    for(int i=1;i<sz(comps);i++){
        pq.push(comps[i].fi-comps[i-1].se);
    }
    while(off>K){
        res+=pq.top();
        off--;
    }
    cout<<res<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    //cin>>t;
    while(t--){
        Solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -