이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<ll,ll> ii;
const ll maxn=300010;
ll n,p[maxn],a[maxn];
priority_queue<ii,vector<ii>,greater<ii>> q;
 int root(int i)
{
    if (p[i] == i) return i;
    return root(p[i]);
}
void merge (long i,long j)
{
    p[root(i)]=p[root(j)];
}
ll b[maxn],k;
int main()
{
 
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for (ll i=1;i<=n;i++) cin>>a[i];
    sort (a+1,a+n+1);
    for (ll i=1;i<n;i++) b[i]=a[i+1]-a[i];
    ll res=0;
    n--;
    sort (b+1,b+n+1);
    for (ll i=1;i<=n-k+1;i++)
    res=res+b[i];
    res+=k;
    cout<<res;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |