Untitled

 avatar
ducsieumanh1hitlanamguku
plain_text
10 days ago
809 B
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
int x[100005],y[10005],m,n,k,q[501];
int find(int a,int b) {
    int nigger=lower_bound(y+1,y+n+1,b-a)-y;
    int t=b-a;
	if (nigger>n) return y[n];
    if (abs(y[nigger]-t)<abs(y[nigger-1]-t)&&nigger<=n) return y[nigger];
    return y[nigger-1];
}
int main() {
    cin>>m>>n>>k;
    for (int i=1;i<=m;i++) {
        cin>>x[i];
    }
    for (int i=1;i<=n;i++) {
        cin>>y[i];
    }
    for (int i=1;i<=k;i++) {
        cin>>q[i];
    }
    sort(x+1,x+m+1);
    sort(y+1,y+n+1);
     for (int i=1;i<=k;i++) {
        int minn=INT_MAX;
        for (int j=1;j<=m;j++) {
            if (minn>abs(q[i]-x[j]-find(x[j],q[i]))) minn=abs(q[i]-x[j]-find(x[j],q[i]));
            if (minn==0) break;
			}
        cout<<minn<<endl;
    }
}
Leave a Comment