Codeforces 831D Office Keys 贪心or dp

https://vjudge.net/problem/CodeForces-831D
这个地方的贪心想不出来。。。

LL a[maxn],b[maxn];
void solve(){
    sort(a+1,a+n+1);
    sort(b+1,b+k+1);
    LL ans=2*inf;
    for(int i=1;i<=k-n+1;++i){
        LL sum=0;
        for(int j=1;j<=n;++j){
            sum=max(sum,abs(a[j]-b[i+j-1])+abs(b[i+j-1]-p));
        }
        ans=min(sum,ans);
    }
    cout<int main(){
    sf("%d%d%d",&n,&k,&p);
    rep(i,1,n)sf("%d",&a[i]);
    rep(i,1,k)sf("%d",&b[i]);
    solve();
}

http://blog.csdn.net/johsnows/article/details/75123572
can dp

你可能感兴趣的:(简单基础经典dp,思维)