# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956138 | manishjha91 | Stove (JOI18_stove) | C++17 | 20 ms | 3364 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>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
// #ifndef ONLINE_JUDGE
// #include "E:\Personal\cpp_codes\debugalgo.h"
// #else
// #define debug(x)
// #endif
//
void solve(int tc)
{
ll n,k;
cin>>n>>k;
vector<ll> a(n);
for(int i=0; i<n; i++)
{
cin>>a[i];
}
sort(a.begin(),a.end());
vector<ll> gap;
for(int i=1; i<n; i++)
{
gap.push_back(a[i]-a[i-1]-1);
}
ll res = n;
ll req = n;
sort(gap.begin(),gap.end());
for(int i=0; i<n-k; i++)
{
res+=gap[i];
}
cout<<res<<"\n";
}
int main()
{
ios_base:: sync_with_stdio(0);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("Error.txt", "w", stderr);
// #endif
int tt = 1;
// cin >> tt;
for(int tc=1; tc<=tt; tc++)
{
solve(tc);
}
}
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... |