# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498913 | Kipras | Swimming competition (LMIO18_plaukimo_varzybos) | C++14 | 1 ms | 204 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>
typedef long long ll;
using namespace std;
const int maxN = 1e6+10;
const int inf = 2147000000;
int n, mini, maxi;
int a[maxN];
bool test(int v){
int i=0, j=0;
bool pos=true;
while(j<n&&pos){
if(i-j==maxi){i=j;/*cout<<i<<" "<<j<<" "<<a[j]-a[i]<<endl;*/}
if(a[j]-a[i]>v){
if(j-i<mini)pos=false;
else {i=j;/*cout<<i<<" "<<j<<" "<<a[j]-a[i]<<endl;*/}
}else j++;
}
if(n-i<mini)pos=false;
return pos;
}
int solve(){
int ans=inf;
int l = 0, h = a[n-1]-a[0];
while(l<h){
int mid = l+((h-l)/2);
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<<test(3);
cout<<solve();
return 0;
}
Compilation message (stderr)
# | 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... |