# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984916 | normankr07 | Stove (JOI18_stove) | C++17 | 15 ms | 3304 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.
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifndef LOCAL
#define cerr \
if (0) \
cerr
#endif
const bool multitest = 0;
const int MAXN = 2e5;
ll t[MAXN];
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> t[i];
}
// Goal, minimize total turned on time
// Active time = t[n] - t[1];
// Got k time -> find the most k diff time to turn off;
vector<ll> diff;
ll sum = t[n] - t[1] + 1;
for (int i = 2; i <= n; i++)
{
diff.push_back(t[i] - t[i - 1]);
}
sort(diff.begin(), diff.end());
while (k-- > 1 && diff.size())
{
sum -= (diff.back() - 1);
diff.pop_back();
}
cout << sum;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
int tc = 1;
if (multitest)
cin >> tc;
while (tc--)
{
solve();
cout << '\n';
}
}
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... |