답안 #966451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966451 2024-04-19T22:42:59 Z m0vlan Stove (JOI18_stove) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
// author: Movlan
#define ll long long
//#define int long long
#define br "\n"
#define sp " "
#define pb push_back
#define pf push_front
typedef pair<ll,int> pii;
#define vi vector<int>;
#define vpii vector<pair<int,int>>
#define all(x) x.begin(),x.end()
#define sync ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
struct edge{
    //int u;
    int v;
    ll w;bool operator<(edge const& other){return w<other.w;}
};


void solve(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    int res=n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector<int>diff;
    for(int i=1;i<n-1;i++){
        diff.pb(arr[i]-arr[i-1]-1);
    }
    sort(all(diff));
    k--;
    int ix=0;
    for(int i=n-2;i>=0 && k;i--){
        k--;
        ix=i;
    }

    int sum=0;
    //cout<<ix<<sp;
    for(int i=0;i<ix;i++){
        //cout<<diff[i]<<br;
        sum+=diff[i];
    }
    cout<<res+sum;
}

signed main() {
    sync;
    int t=1;
    //cin >> t;
    while(t--){
        solve();
        //cout<<br;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -