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>
typedef long long ll;
using namespace std;
const int maxN = 1e6+10;
const int inf = 2147000000;
int n, mini, maxi;
int a[maxN];
int dp[maxN];
bool test(int v){
fill(dp, dp+maxN, 0);
dp[0]=1;
int i, j;
for(i = 0; i < n; i++){
if(i>1)dp[i]+=dp[i-1];
if(dp[i]<=0)continue;
j=i;
while(j<n&&a[j]-a[i]<=v)j++;
if(i+mini<=min(i+maxi, j)){
dp[i+mini]++;
dp[min(i+maxi, j)+1]--;
}
}
dp[n]+=dp[n-1];
return dp[n]>0;
}
int solve(){
int l = -1, h = inf;
while(l<h-1){
int mid = (h+l)/2;
if(test(mid))h=mid;
else l=mid;
}
return h;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n>>mini>>maxi;
for(int i = 0; i < n; i++)cin>>a[i];
sort(a, a+n);
cout<<solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |