# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943561 | vjudge1 | Stove (JOI18_stove) | C++17 | 16 ms | 2304 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 pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x << " = " << x << endl;
# define pll pair <ll, ll>
# define pii pair <int, int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = (ll)1e5 + 3;
const ll inf = (ll)2e18 + 0;
const ll mod = (ll)1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const bool T = 0;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void Freopen () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int n, k, t[maxn];
void ma1n () {
cin >> n >> k;
vector <int> e;
for (int i = 1; i <= n; ++i) {
cin >> t[i];
if (i > 1) e.pb(t[i] - t[i - 1] - 1);
}
sort(e.rbegin(), e.rend());
int ans = t[n] + 1 - t[1];
for (int i = 0; i < min(sz(e), k - 1); ++i) ans -= e[i];
cout << ans << nl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// Freopen();
int ttt = 1;
if (T) cin >> ttt;
for (int test = 1; test <= ttt; ++test) {
// cout << "Case " << test << ":" << '\n';
ma1n();
}
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... |