# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1241433 | tminh | Stove (JOI18_stove) | C++20 | 12 ms | 1480 KiB |
/*
Em la may troi trong gio
Anh la cay nhieu dan do
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define ep emplace_back
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const signed N = 1e6 + 5;
const ll oo = 1e18;
int n, k, t[N];
vector<int> arr;
void output() {
int total = (t[n] - t[1] + 1);
for (int i = 2; i <= n; ++i) arr.pb(t[i] - (t[i - 1] + 1));
sort(vall(arr), greater<int>());
for (int i = 0; i < k; ++i) total -= arr[i];
cout << total;
return;
}
void input() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> t[i];
--k;
output();
return;
}
signed main() {
if(fopen("", "r")) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << 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... |