제출 #1251736

#제출 시각아이디문제언어결과실행 시간메모리
1251736aegWatching (JOI13_watching)C++20
50 / 100
831 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, p, q;
  cin >> n >> p >> q;
  vector<int> a(n);
  for(auto &x:a) cin >> x;
  sort(a.begin(), a.end());

  int l = 1, r = 1e9;
  int ans = INT_MAX;
  while (r - l >= 0) {
    int m = (l + r) / 2;
    vector<vector<int>> dp(n, vector<int>(p + 1, 0));
    int pp = 0, qp = 0;
    for (int i = 0; i < n; i++) {
      while(a[i] - a[pp] >= m) pp++;
      while(a[i] - a[qp] >= 2 * m) qp++;
      for (int j = 0; j <= p; j++) {
        if (j == 0) {
          if (qp == 0)
	    dp[i][j] = 1;
	  else
	    dp[i][j] = dp[qp - 1][j] + 1;
        } else if (pp == 0)
          dp[i][j] = 0;
        else if (qp == 0)
	  dp[i][j] = min(dp[pp - 1][j - 1], 1);
	else
	  dp[i][j] = min(dp[pp - 1][j - 1], dp[qp - 1][j] + 1);
      }
    }
    int mini = *min_element(dp[n - 1].begin(), dp[n - 1].end());
    if (mini <= q) {
      r = m - 1;
      ans = min(ans, m);
    } else {
      l = m + 1;
    }
  }
  cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...