# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55899 | YaDon4ick | Stove (JOI18_stove) | C++14 | 45 ms | 1656 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.
//By Don4ick
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
using namespace std;
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int n, k;
scanf("%d%d", &n, &k);
vector < int > a(n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(all(a));
vector < int > b;
for (int i = 1; i < n; i++)
b.pb(a[i] - a[i - 1] - 1);
sort(all(b));
int ans = n;
for (int i = 0; i < n - k; i++)
ans += b[i];
cout << ans << endl;
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... |