-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf-div2.cpp
More file actions
67 lines (64 loc) · 1.44 KB
/
Copy pathcf-div2.cpp
File metadata and controls
67 lines (64 loc) · 1.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll x;
cin>>x;
while(x--){
ll n,m,q;
cin>>n>>m>>q;
vector<ll>nums(m);
for(int i=0;i<m;i++){
cin>>nums[i];
}
vector<ll>queries(q);
for(int i=0;i<q;i++){
cin>>queries[i];
}
sort(nums.begin(),nums.end());
for(int i=0;i<queries.size();i++){
ll cell=queries[i];
ll startingPositon;
auto startIndex = lower_bound(nums.begin(),nums.end(),cell);
if(startIndex == nums.begin()){
startingPositon = -1;
}
else if (startIndex != nums.end() && *startIndex == cell) {
--startIndex;
--startIndex;
int pos = startIndex-nums.begin();
startingPositon=nums[pos];
}
else{
--startIndex;
int pos = startIndex-nums.begin();
startingPositon=nums[pos];
}
ll lastIndex = upper_bound(nums.begin(),nums.end(),cell-1)-nums.begin();
ll lastPositon;
if(lastIndex == nums.size()){
lastPositon = -1;
}
else{
lastPositon = nums[lastIndex];
}
ll ans =0;
if(startingPositon==-1){
ans=max(ans*1ll,(lastPositon-1)*1ll);
}
else if(lastPositon==-1){
ans=max(ans,n-startingPositon);
}
else{
ll stay = min((lastPositon-cell)*1ll, (cell-startingPositon)*1ll);
ll temp= stay-1;
ll maxStay = max((lastPositon-cell)*1ll, (cell-startingPositon)*1ll);
maxStay-=temp;
ll move = temp+ (maxStay/2 + maxStay%2);
ans=max(stay,move);
}
cout<<ans<<endl;
}
}
return 0;
}