Submission #1332229

#TimeUsernameProblemLanguageResultExecution timeMemory
1332229cpismayilmmdv985Stove (JOI18_stove)C++20
0 / 100
1 ms344 KiB
#ifdef LOCAL
#include ".debug.hpp"
#else
#define debug(...) 42
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

signed main() {
#ifndef VOID
   cin.tie(nullptr)->sync_with_stdio(false);
#endif

   int N, K;   cin >> N >> K;
   vector<int64_t> A(N); for (auto &a : A) cin >> a;
   auto check = [&](const int64_t &target) -> array<int64_t, 2> {
      int cnt = 1;
      int64_t L = A[0], res = 0;
      for (int i = 1; i < N; i++) {
         if (A[i] - L + 1 <= target)   continue;
         else                          res += (A[i - 1] - L + 1), cnt++, L = A[i];
      }
      res += A.back() - L + 1;
      return {cnt <= K, res};
   };
   int64_t low = 1, high = INT_MAX, mid, best = INT_MAX;
   while (low <= high) {
      mid = (low + high) >> 1;
      array<int64_t, 2> res = check(mid);
      debug(mid); debug(res);
      if (res[0]) best = res[1], high = mid - 1;
      else        low = mid + 1;
   }
   cout << best;

   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...