# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64458 | elitewantsyou | Stove (JOI18_stove) | C++14 | 43 ms | 10476 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 fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
const long long N = 100100;
const long long Q = N * 30;
const long long mod = 998244353;
const long long MAGIC = 30;
using namespace std;
int n;
int k;
int a[N];
vector < int > v;
void solve()
{
cin >> n >> k;
long long ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 2; i <= n; i++){
ans += a[i] - a[i - 1];
v.push_back(a[i] - a[i - 1]);
}
sort(v.begin(), v.end());
while(v.size() > n - k){
ans -= v.back();
v.pop_back();
}
cout << ans + k << "\n";
}
bool mtest = false; int main()
{
//fin("input.txt");
//fout("output.txt");
//fin("island.in");
//fout("island.out");
ios_base::sync_with_stdio(0);
int TE = 1;
if(mtest)
cin >> TE;
while(TE--)
solve();
return 0;
}
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... |