# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330020 | sazid_alam | Stove (JOI18_stove) | C++17 | 25 ms | 3200 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.
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
#define pb push_back
#define pf push_front
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define Tcase() int t; cin >> t; while(t--)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
const ll MOD = 1e9 + 7; //998244353;
const ll INF = 1e18;
const int MX = 2e5 + 5;
const ld PI = acos((ld) -1);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int main(){
setIO();
ll n, k;
cin >> n >> k;
ll a[n] = {0};
F0R(i, n) cin >> a[i];
sort(a, a + n);
vector<ll> Diff;
FOR(i, 1, n) Diff.pb(a[i] - a[i - 1]);
sort(all(Diff));
ll Ans = n;
F0R(i, n - k) Ans += Diff[i] - 1;
cout << Ans;
}
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... |