-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintervals.cpp
More file actions
54 lines (46 loc) · 1.24 KB
/
intervals.cpp
File metadata and controls
54 lines (46 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
vector<pair<int,int>>intervals;
for(int i=0;i<n;i++)
{
int arr,dep;
cin>>arr>>dep;
intervals.push_back(make_pair(arr,dep));
}
sort(intervals.begin(),intervals.end());
while(m--)
{
int current_m;
cin>>current_m;
int position=lower_bound(intervals.begin(),intervals.end(),make_pair(current_m,0))-intervals.begin();
if(position==0)
{
cout<<intervals[0].first-current_m<<endl;
}
else
{
int ans=-1;
if(intervals[position-1].second>current_m)
{
ans=0;
// cout<<ans<<endl;
}
else if(position<intervals.size())
{
ans=intervals[position].first-current_m;
// cout<<ans<<endl;
}
cout<<ans<<endl;
}
}
}
return 0;
}