# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
463627 | NintsiChkhaidze | Stove (JOI18_stove) | C++14 | 26 ms | 3240 KiB |
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 ll long long
#define pb push_back
#define pi pair<int,int>
#define s second
#define f first
#define int ll
using namespace std;
const int N = 100005;
int a[N];
vector <int> v;
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,k;
cin>>n>>k;
for (int i = 1; i <= n; i++)
cin>>a[i];
if (k == n){
cout<<n;
return 0;
}
sort(a + 1,a + n + 1);
int res= a[n] + 1 - a[1];
for (int i = 2; i <= n; i++)
v.pb(a[i] - a[i - 1] - 1);
sort(v.begin(),v.end());
for (int i = v.size() - 1; i >= v.size() - k + 1; i--)
res -= v[i];
cout<<res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |