이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long
#define pi pair<int, int>
#define mp make_pair
#define ld long double
const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;
//
void solve()
{
int n, k;
cin>>n>>k;
vector<int> t(n+1, 0);
for(int i=1; i<=n; i++)
{
cin>>t[i];
}
sort(t.begin()+1, t.end());
vector<int> d(0);
int tot = t.back() + 1 - t[1];
for(int i=1; i<n; i++)
{
d.pb(t[i+1] - t[i] - 1);
}
sort(d.begin(), d.end());
int cnt = 1;
while(cnt<k && (not d.empty()))
{
tot -= d.back();
//cerr<<d.back()<<"\n";
d.pop_back();
cnt++;
}
cout<<tot;
}
signed main()
{
fast_io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
cout<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |