Submission #792435

# Submission time Handle Problem Language Result Execution time Memory
792435 2023-07-25T04:53:28 Z vjudge1 Stove (JOI18_stove) C++17
0 / 100
1 ms 212 KB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector < int > a(n);
    for(auto &i : a) {
        cin >> i;
    }
    ll l = 0, r = 1e9, m, t;
    for(; l + 1 < r;) {
        m = (l + r) / 2;
        t = 1;
        for(int i = 1, j = 0; i < n; ++ i) {
            if(a[i] - a[j] + 1 > m) {
                ++ t;
                j = i;
            }
        }
        (t > k ? l : r) = m;
    }
    ll ans = 0, i = 1, j = 0;
    for(; i < n; ++ i) {
        if(a[i] - a[j] + 1 > r) {
            ans += a[i - 1] - a[j] + 1;
            j = i;
        }
    }
    cout << ans + (a.back() - a[j] + 1);
}

Compilation message

stove.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -