-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChef restaurant
55 lines (54 loc) · 1.42 KB
/
Chef restaurant
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
55
#include <bits/stdc++.h>
using namespace std;
#define read(type) readInt<type>() // Fast read
#define ll long long
#define nL "\n"
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define a first
#define b second
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))
int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int ttt; cin >> ttt;
while(ttt--) {
int n,m;
cin>>n>>m;
vector<pair<int,int>> times(n);
for(int i=0;i<n;i++){
cin>>times[i].first>>times[i].second;
}
vector<int> nums(m);
for(int i=0;i<m;i++){
cin>>nums[i];
}
sort(times.begin(),times.end());
for(int i=0;i<m;i++){
int pos=lower_bound(times.begin(),times.end(),make_pair(nums[i],0))-times.begin();
if(pos==0){
int ans=times[0].first-nums[i];
cout<<ans<<endl;
}else {
if(times[pos-1].second>nums[i]){
cout<<0<<endl;
}else if(pos<times.size()){
cout<<times[pos].first-nums[i]<<endl;
}else{
cout<<-1<<endl;
}
}
}
}
return 0;
}