Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define loop(i,a,b) for(int i=(a);i<=(b);i++)
- #define read(a,n) for(int i=0;i<n;i++) cin>>a[i];
- #define setbits(n) __builtin_popcount(n)
- #define lsetbits(n) __buitin_popcountll(n)
- #define pb push_back
- typedef long long int ll;
- typedef struct interval{
- ll start;
- ll end;
- }prob;
- bool compare(prob x,prob y){
- if(x.start<y.start) return true;
- else return false;
- }
- ll waitingtime(prob a[],int index,int n,ll t){
- // cout<<t<<" "<<index<<endl;
- if(index==0){
- return a[0].start-t;
- }
- else{
- if(a[index-1].end>=t) return 0;
- else{
- if(index==n) return -1;
- else return a[index].start-t;
- }
- }
- }
- int main(){
- int t;
- cin>>t;
- while(t--){
- int n,m;
- cin>>n>>m;
- prob a[n];
- ll time[m];
- loop(i,0,n-1){
- ll x,y;
- cin>>x>>y;
- a[i].start=x;
- a[i].end=(y-1);
- }
- sort(a,a+n,compare);
- loop(i,0,m-1){
- cin>>time[i];
- int l=0,r=n-1;
- int index=n;
- while(l<=r){
- int mid=l+(r-l)/2;
- if(a[mid].start>=time[i]){
- index=mid;
- r=mid-1;
- }
- else{
- l=mid+1;
- }
- }
- ll ans=waitingtime(a,index,n,time[i]);
- cout<<ans<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment