답안 #899218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899218 2024-01-05T15:45:22 Z Blagoj Stove (JOI18_stove) C++17
0 / 100
0 ms 348 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] = {1 + c, 1};
    for (int i = 1; i < n; i++) {
        ll opt1 = dp[i - 1].first + c + 1;
        ll opt2 = dp[i - 1].first + v[i] - v[i - 1];
        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];
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -