Submission #1099542

#TimeUsernameProblemLanguageResultExecution timeMemory
1099542crispxxStove (JOI18_stove)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define vt vector #define nl " \n" #define pb emplace_back #define all(x) x.begin(), x.end() template <class F, class S> void chmin(F &a, S b) { if(a > b) a = b; } template <class F, class S> void chmax(F &a, S b) { if(a < b) a = b; } void run_case() { int n, k; cin >> n >> k; vt<int> a(n); for(auto &i : a) { cin >> i; } auto f = [&](int x) -> pair<int, int> { int tot = 0, cnt = 1, j = 0, mx = 0; for(int i = 0; i < n; i++) { if(a[i] - a[j] > x) { tot += mx; mx = 0; j = i; cnt++; } chmax(mx, a[i] - a[j] + 1); } return {cnt, tot + mx}; }; int l = 0, r = *max_element(all(a)); while(l < r) { int mid = (l + r) / 2; if(f(mid).first <= k) { r = mid; } else { l = mid + 1; } } cout << f(r).second << nl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; // cin >> tt; for(int i = 0; i < tt; i++) { run_case(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...