Submission #359300

#TimeUsernameProblemLanguageResultExecution timeMemory
359300PetyWatching (JOI13_watching)C++14
100 / 100
199 ms8684 KiB
#include <bits/stdc++.h>

using namespace std;

int n, p, q, a[2002], dp[2002][2002], next1[2002], next2[2002];

int main()
{
  cin >> n >> p >> q;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  if (p + q >= n) {
    cout << 1;
    return 0;
  }
  int st = 1, dr = 1e9, ans = 0;
  while (st <= dr) {
    int mij = (st + dr) / 2;
    for (int i = 1; i <= n; i++) {
      next1[i] = lower_bound(a + 1, a + n + 1, a[i] + mij) - a - 1;
      next2[i] = lower_bound(a + 1, a + n + 1, a[i] + 2 * mij) - a - 1;
    }
    next1[n + 1] = next2[n + 1] = n;
    for (int i = 0; i <= p; i++)
      for (int j = 0; j <= q; j++) {
        if (!i && !j)
          continue;
        dp[i][j] = 0;
        if (i)
          dp[i][j] = next1[dp[i - 1][j] + 1];
        if (j)
          dp[i][j] = max(dp[i][j], next2[dp[i][j - 1] + 1]);
      }
    if (dp[p][q] < n) {
      st = mij + 1;
    }
    else {
      ans = mij;
      dr = mij - 1;
    }
  }
  cout << ans;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...