# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863942 | prohacker | Watching (JOI13_watching) | C++14 | 204 ms | 16216 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2010;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,p,q,a[N];
int dp[N][N];
bool check(int mid) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 0 ; j <= q ; j++) {
dp[i][j] = mod;
}
}
for(int i = 1, j = 1, k = 1 ; i <= n ; i++) {
while(j < i && a[i]-a[j] >= mid) {
j++;
}
while(k < i && a[i]-a[k] >= mid*2) {
k++;
}
for(int l = 0 ; l <= q ; l++) {
dp[i][l] = dp[j-1][l]+1;
}
for(int l = 0 ; l <= q ; l++) {
dp[i][l+1] = min(dp[i][l+1],dp[k-1][l]);
}
}
for(int i = 0 ; i <= q ; i++) {
if(dp[n][i] <= p) {
return true;
}
}
return false;
}
signed main()
{
if (fopen("WATCHING.inp", "r")) {
freopen("WATCHING.inp", "r", stdin);
freopen("WATCHING.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> p >> q;
if(n <= p+q) {
cout << 1;
return 0;
}
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
sort(a+1,a+n+1);
int l = 1;
int r = 1e9;
int ans;
while(l <= r) {
int mid = l + r >> 1;
if(check(mid)) {
ans = mid;
r = mid-1;
}
else {
l = mid+1;
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |