Submission #499111

#TimeUsernameProblemLanguageResultExecution timeMemory
499111KiprasSwimming competition (LMIO18_plaukimo_varzybos)C++14
100 / 100
434 ms14856 KiB
#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=1; for(i = 0; i < n; i++){ if(i>1)dp[i]+=dp[i-1]; if(dp[i]<=0)continue; j=max(j, i+1); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...