//GETTING WRONG ANSWER IN 2 TEST CASES#include<bits/stdc++.h>#define FOR0(i,n) for(int i=0;i<n;i++)using namespace std;#define vi vector<int>#define pb push_back#define ll long longint main(){ int n,x,y; cin>>n>>x>>y; int s[n],e[n]; FOR0(i,n){ cin>>s[i]>>e[i]; } int v[x],u[y]; FOR0(i,x) cin>>v[i]; sort(v,v+x); FOR0(i,y) cin>>u[i]; sort(u,u+y); // function to find wormhole lesser than s[i] // function to find wormhole greater than e[i] int time[n]; FOR0(i,n){ int l1=0,r1=x-1,x1; while(l1<r1){ x1=(l1+r1+1)/2; if (v[x1]<=s[i]) l1=x1; else r1=x1-1; } int l2=0,r2=y-1,x2; while(l2<r2){ x2=(l2+r2)/2; if (u[x2]>=e[i]) r2=x2; else l2=x2+1; } //cout<<l1<<' '<<l2<<endl; time[i]=u[l2]-v[l1]+1; //cout<<time[i]<<endl; } sort(time,time+n); cout<<time[0]; }
Read more…