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>
#pragma GCC optimize("O3")
using namespace std;
typedef long long int ll;
typedef long double ldb;
typedef unsigned long long uli;
#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define DF(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mp make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define y1 adjf
#define tm dhgdg
const int MAXN = 2e3 + 3;
int n, p, q;
int a[MAXN];
int dp[MAXN][MAXN];
int jump[2][MAXN];
bool can(int w){
jump[0][n - 1] = jump[1][n - 1] = n - 1;
int ptr[2] = {n-1, n-1};
DF(i, n - 2, -1){
while(ptr[0] > i && a[ptr[0]] - a[i] >= w)ptr[0]--;
jump[0][i] = ptr[0];
while(ptr[1] > i && a[ptr[1]] - a[i] >= 2*w)ptr[1]--;
jump[1][i] = ptr[1];
}
F(i, 0, min(p,n)+1)F(j, 0, min(q,n)+1)dp[i][j] = 0;
F(i, 0, min(p, n) + 1){
F(j, 0, min(q, n) + 1){
if(dp[i][j] == n)ret true;
if(i < min(p, n)){
dp[i+1][j] = max(dp[i+1][j], jump[0][dp[i][j]]+1);
}
if(j < min(q, n)){
dp[i][j+1] = max(dp[i][j+1], jump[1][dp[i][j]]+1);
}
}
}
ret false;
}
int main(){
scanf("%d%d%d", &n, &p, &q);
F(i, 0, n)scanf("%d", &a[i]);
sort(a, a + n);
int l = 0, r = 6e8;
while(r - l > 1){
int mid = (l + r) >> 1;
if(can(mid))r = mid;
else l = mid;
}
printf("%d", r);
ret 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:62:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &p, &q);
^
watching.cpp:63:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
F(i, 0, n)scanf("%d", &a[i]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |