제출 #1334360

#제출 시각아이디문제언어결과실행 시간메모리
1334360iamhereforfunStove (JOI18_stove)C++20
100 / 100
14 ms1216 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int LG = 60;
const int INF = 1e9 + 5;
const int K = 301;
const int B = 150000;
const int MOD = 1e9 + 7;

int n, k, a[N], dis[N], ans;

inline void solve()
{
    cin >> n >> k;
    for (int x = 0; x < n; x++)
    {
        cin >> a[x];
    }
    sort(a, a + n);
    ans = n;
    for (int x = 0; x < n - 1; x++)
    {
        dis[x] = a[x + 1] - a[x];
    }
    sort(dis, dis + n - 1);
    for (int x = 0; x < n - k; x++)
    {
        ans += dis[x] - 1;
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...