| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1295079 | dominus_oj | Stove (JOI18_stove) | C++20 | 14 ms | 2432 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(s) s.begin(), s.end()
#define endl '\n'
#define pb(x) push_back(x)
#define f first
#define s second
#define yes "YES"
#define no "NO"
#define sz(x) (int)x.size()
typedef pair<int, int> pii;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const double EPS = 1e-7;
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void solve() {
int n, k; cin >> n >> k;
vi a(n);
for (int i=0; i<n; i++) cin >> a[i];
vi b;
for (int i=0; i<n-1; i++) {
b.push_back(a[i+1] - a[i]);
}
sort(all(b));
int ans = 0;
for (int i=0; i<n-k; i++) {
ans += b[i];
}
cout<<ans+k<<endl;
}
signed main() {
// setIO("");
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
while (t--) 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... | ||||
