This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fore(i,a,b) for(lli i = (a), abcdxd = (b); i < abcdxd; i++)
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define sz(v) lli((v).size())
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using namespace std;
typedef long long lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef long double ld;
#define deb(x) cout << #x << ": " << x << ENDL;
int main(){ _
lli n, k; cin >> n >> k;
vi v;
lli ans = 1ll;
{
vi b(n); for (auto & i : b) cin >> i; sort(all(b));
fore(i,1,n){
if (b[i] == b[i - 1]) continue;
ans++;
v.pb(b[i] - (b[i - 1] + 1ll));
}
}
sort(all(v));
fore(i,0,max(0ll, sz(v) - k + 1ll)) ans += v[i];
cout << ans << ENDL;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |