이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
void solve(){
ll n,p,q; cin>>n>>p>>q;
ll a[n+1];
forp(i,1,n){
cin>>a[i];
}
if(p+q>=n){
cout<<1<<newl; return;
}
sort(a+1,a+n+1);
a[0]=0;
ll w1=1,w2=a[n]-a[1];
ll w,i1,i2;
while(w1<w2){
w=(w1+w2)/2;
ll dp[p+1][q+1];
memset(dp,0,sizeof(dp));
bool g=0;
forp(i,0,p){
if(g){break;}
forp(j,0,q){
i1=i2=0;
if(j){
//cout<<dp[i][j-1]<<newl;
i1 = upper_bound(a+1,a+n+1,a[dp[i][j-1]+1]+2*w-1)-a; i1--; //cout<<i1<<" ";
}
if(i){
//cout<<dp[i-1][j]<<newl;
i2 = upper_bound(a+1,a+n+1,a[dp[i-1][j]+1]+w-1)-a; i2--; //cout<<i2<<newl;
}
dp[i][j]=max(i1,i2);
if(dp[i][j]==n){
g=1; break;
}
}
}
if(g||dp[p][q]==n){
w2=w;
} else {
w1=w+1;
}
}
cout<<w1<<newl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |