Submission #359300

# Submission time Handle Problem Language Result Execution time Memory
359300 2021-01-26T17:11:29 Z Pety Watching (JOI13_watching) C++14
100 / 100
199 ms 8684 KB
#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 time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 24 ms 1260 KB Output is correct
9 Correct 26 ms 3820 KB Output is correct
10 Correct 44 ms 8684 KB Output is correct
11 Correct 40 ms 1004 KB Output is correct
12 Correct 199 ms 8044 KB Output is correct
13 Correct 7 ms 364 KB Output is correct
14 Correct 8 ms 492 KB Output is correct
15 Correct 8 ms 364 KB Output is correct