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 ans=inf;
int l = 0, h = inf;
while(l<h){
int mid = l+((h-l)/2);
//cout<<l<<" "<<mid<<" "<<h<<" "<<test(mid)<<endl;
if(test(mid))h=mid;
else l=mid+1;
}
return l;
}
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;
}
Compilation message (stderr)
plaukimo_varzybos.cpp: In function 'int solve()':
plaukimo_varzybos.cpp:38:9: warning: unused variable 'ans' [-Wunused-variable]
38 | int ans=inf;
| ^~~
# | 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... |