Submission #306138

#TimeUsernameProblemLanguageResultExecution timeMemory
306138quocnguyen1012Watching (JOI13_watching)C++14
100 / 100
222 ms16120 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 2005;

int f[maxn][maxn];
int a[maxn], N;
int P, Q;

bool check(int len)
{
  const int inf = 1e9;
  int l = 1, r = 1;
  for (int i = 1; i <= N; ++i){
    while (l <= N && a[l] < a[i] - len + 1) ++l;
    while (r <= N && a[r] < a[i] - 2 * len + 1) ++r;
    for (int j = 0; j <= P; ++j){
      f[i][j] = inf;
      if (j > 0) f[i][j] = min(f[i][j], f[l - 1][j - 1]);
      f[i][j] = min(f[i][j], f[r - 1][j] + 1);
    }
  }
  return f[N][P] <= Q;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> P >> Q;
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  sort(a + 1, a + 1 + N);
  if (P + Q >= N) {
    cout << 1;
    return 0;
  }
  int l = 1, r = 1e9, mid;
  while (l <= r){
    mid = (l + r) / 2;
    if (!check(mid)) l = mid + 1;
    else r = mid - 1;
  }
  cout << l;
}

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     freopen("A.INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     freopen("A.OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...