제출 #1327521

#제출 시각아이디문제언어결과실행 시간메모리
1327521tuncay_pasha구경하기 (JOI13_watching)C++20
100 / 100
568 ms32072 KiB
/**
 * author:  tuncypasha
 * file:    c.cpp
 * created: 22.02.2026 10:26
**/
#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

constexpr int N = 1e+7 + 5, oo = 1e+16;

void _() {
  int n, p, q;
  cin >> n >> p >> q;
  p = min(p, n), q = min(q, n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(all(a));
  int lo = 1, hi = 1e9, ans = 1e9;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    vector<int> nxtp(n), nxtq(n);
    for (int i = 0; i < n; ++i) {
      nxtp[i] = upper_bound(all(a), a[i] + mid - 1) - a.begin();
      nxtq[i] = upper_bound(all(a), a[i] + mid * 2 - 1) - a.begin();
    }
    vector<vector<int>> dp(n + 5, vector<int>(p + 5, oo));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= p; ++j) {
        if (dp[i][j] >= oo)
          continue;
        if (j + 1 <= p)
          dp[nxtp[i]][j + 1] = min(dp[nxtp[i]][j + 1], dp[i][j]);
        dp[nxtq[i]][j] = min(dp[nxtq[i]][j], dp[i][j] + 1);
      }
    }
    bool ok = false;
    for (int i = 0; i <= p; ++i) {
      if (dp[n][i] <= q)
        ok = true;
    }
    if (ok) {
      ans = mid;
      hi = mid - 1;
    }
    else lo = mid + 1;
  }
  cout << ans << '\n';
}

signed main() {
  pasha
  int t = 1;
  // cin >> t;
  for (int cs = 1; cs <= t; ++cs) {
    _();
    // cout << '\n';
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...