Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a,b;
- cin>>a;
- int x[a];
- for(int i=0;i<a;i++)
- {
- cin>>x[i];
- }
- sort(x,x +a);
- cin>>b;
- int y[b];
- for(int j=0;j<b;j++)
- {
- cin>>y[j];
- }
- sort(y,y +b);
- int l=0;
- int r=b-1;
- int mid;
- int najmal=2000000000;
- int broj=-1;
- for(int i=0;i<a;i++)
- {
- l=0;
- r=b-1;
- while(l<=r)
- {
- mid=(r+l)/2;
- if(y[mid]<x[i])
- {
- l=mid+1;
- }
- if(y[mid]>=x[i])
- {
- if(najmal > y[mid]-x[i])
- {
- najmal=y[mid]-x[i];
- broj=x[i];
- }
- if(najmal == y[mid] - x[i] and broj < x[i]) {
- broj = x[i];
- }
- r=mid-1;
- }
- }
- // cout << x[i] /<< " " << najmal << endl;
- }
- cout<<broj << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement