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 int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
int n, p, q;
vector<int> v;
int ct[2005][2];
int makect(int w){
for(int i = 1;i<=n;i++){
auto it = lower_bound(v.begin(), v.end(), v[i] + w);
it--;
int ind = it - v.begin();
ct[i][0] = ind;
it = lower_bound(v.begin(), v.end(), v[i] + w + w);
it--;
ind = it - v.begin();
ct[i][1] = ind;
}
}
bool f(int w){
makect(w);
int dp[p+1][q+1];
dp[0][0] = 0;
for(int i = 0;i<=p;i++){
for(int j = 0;j<=q;j++){
if(i==0 && j==0) continue;
dp[i][j] = -INF;
if(i>0){
dp[i][j] = max(dp[i][j], ct[dp[i-1][j]+1][0]);
}
if(j>0){
dp[i][j] = max(dp[i][j], ct[dp[i][j-1]+1][1]);
}
if(dp[i][j] == n) return true;
}
}
return false;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>p>>q;
int a[n];
for(int i = 0;i<n;i++) cin>>a[i];
sort(a, a+n);
v.push_back(-1);
for(int i = 0;i<n;i++) v.push_back(a[i]);
p = min(p, n);
q = min(q, n);
int l = 1;
int u = 1e9;
int ans = 1e9;
while(l<=u){
int mid = mid(l, u);
bool cando = f(mid);
if(cando){
ans = min(ans, mid);
u = mid - 1;
}
else l = mid + 1;
}
cout<<ans<<"\n";
}
Compilation message (stderr)
watching.cpp: In function 'long long int makect(long long int)':
watching.cpp:25:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |