Submission #899207

# Submission time Handle Problem Language Result Execution time Memory
899207 2024-01-05T15:34:16 Z Blagoj Stove (JOI18_stove) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

ll n, k, c;
vector<ll> v;

pair<ll, ll> solve() {
    pair<ll, ll> dp[n];
    dp[0] = {3 + c, 1};
    for (int i = 1; i < n; i++) {
        ll opt1 = dp[i - 1].first + c + 2;
        ll opt2 = dp[i - 1].first + v[i] - v[i - 1] - 2;
        if (opt1 < opt2) dp[i] = {opt1, dp[i - 1].second + 1};
        else dp[i] = {opt2, dp[i - 1].second};
    }
    return dp[n - 1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(all(v));
    ll lb = -1e14, rb = 1e14, res = 1e14;
    while (lb + 1 < rb) {
        c = (lb + rb) / 2;
        pair<ll, ll> ans = solve();
        if (ans.second > k) lb = c;
        else {
            res = min(res, ans.first - ans.second * c);
            rb = c;
        }
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -