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>
using namespace std;
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
int n,sm,big,arr[2001],dp[2001][2001],mid;
int check(int idx,int small){
if (small < 0) return 1e10;
if (idx == -1) return 0;
int &ret = dp[idx][small];
if (~ret) return ret;
int idx1 = idx, idx2 = idx;
while(idx1 >= 0 && arr[idx] - arr[idx1] < mid)
idx1--;
while(idx2 >= 0 && arr[idx] - arr[idx2] < 2*mid)
idx2--;
return ret = min(check(idx1, small-1), check(idx2, small)+1);
}
bool ok(){
memset(dp,-1,sizeof dp);
for (int i = 0; i <= sm; i++) {
check(n-1, i);
}
for (int i = 0; i <= sm; i++) {
if (dp[n-1][i] <= big)
return 1;
}
return 0;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
n=nxt(),sm=nxt(),big=nxt();
if(n<big)big=n;
if(n<sm)sm=n;
gen(arr,n,nxt);
sort(arr,arr+n);
mid = 2;
int s=0,e=1e9,mn=1e9;
while(s<=e){
if(e==1)break;
mid=(s+e)>>1;
if(ok()){
mn=min(mn,mid);
e=mid-1;
}
else s=mid+1;
}
cout<<mn;
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |