제출 #477660

#제출 시각아이디문제언어결과실행 시간메모리
477660chungdinhStove (JOI18_stove)C++14
100 / 100
55 ms1932 KiB
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <cassert>
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll long long
#define ii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define r first
#define c second

#define all(x) x.begin(), x.end()

ostream& operator << (ostream& os, pair<int, int> a) {
    return os << a.first << " : " << a.second;
}

#define endl '\n'
#define db(val) "["#val" = "<<(val)<<"] "
#define cntbit(x) __builtin_popcount(x)

const int N = 2e5 + 5;
const int iINF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int n, k;
ll a[N];

ll t[N];

int main() {
    #ifndef ONLINE_JUDGE
    //freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);
    #endif

    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);

    for (int i = 1; i <= n - 1; i++) t[i] = a[i + 1] - 1 - (a[i] + 1) + 1;
    sort(t + 1, t + n, greater<ll>());

    cout << a[n] - a[1] + 1 - accumulate(t + 1, t + (k - 1) + 1, 0);
}

/*
Array bounds *
long long vs int
Garbage value
Sometimes, VNOI views "arrays out of bounds" as "wrong answer"
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...