| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1335447 | Bilolbek11 | Stove (JOI18_stove) | C++20 | 15 ms | 4412 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(s) s.begin(), s.end()
#define endl '\n'
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define vch vector<char>
#define ss second
#define ff first
#define vld vector<long double>
#define vs vector<string>
#define pb push_back
#define pp pop_back
#define pii pair<int, int>
#define vpp vector<pair<int, int>>
#define mp make_pair
#define sz(x) (int)x.size()
#define pi 3.14159265358979323846
string yes = "YES";
string no = "NO";
const int mod = 1e9 + 7;
const int mxN = 1e5 + 1;
const int inf = 1e18;
void setIO(string s)
{
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void txt()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
struct gap {
int s, e, d;
bool operator<(const gap& o) const {
return d < o.d;
}
};
void solve()
{
int n, k;
cin >> n >> k;
vi a(n);
for (int i = 0;i < n;i++) {
cin >> a[i];
}
vector<gap> g;
for (int i = 0;i < n - 1;i++) {
g.pb({ i,i + 1,a[i + 1] - a[i] + 1 });
}
sort(all(g));
int cur = n;
int total = n;
int i = 0;
while (cur > k) {
gap c = g[i];
i++;
cur--;
total -= 2;
total += (a[c.e] - a[c.s] + 1);
}
cout << total;
}
signed main()
{
// txt();
// setIO("problemname");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
auto start = chrono::high_resolution_clock::now();
int t = 1;
//cin >> t;
while (t--)
{
solve();
cout << endl;
}
#ifdef Bilol
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << "Time: " << (double)duration.count() << " ms" << endl;
#endif
}
/*
██████╗░██╗██╗░░░░░░█████╗░██╗░░░░░██████╗░███████╗██╗░░██╗
██╔══██╗██║██║░░░░░██╔══██╗██║░░░░░██╔══██╗██╔════╝██║░██╔╝
██████╦╝██║██║░░░░░██║░░██║██║░░░░░██████╦╝█████╗░░█████═╝░
██╔══██╗██║██║░░░░░██║░░██║██║░░░░░██╔══██╗██╔══╝░░██╔═██╗░
██████╦╝██║███████╗╚█████╔╝███████╗██████╦╝███████╗██║░╚██╗
╚═════╝░╚═╝╚══════╝░╚════╝░╚══════╝╚═════╝░╚══════╝╚═╝░░╚═╝
*/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... | ||||
