#include<bits/stdc++.h>
using namespace std;
long long n;
long long cal(long long x,long long y){
return min(2*n-abs(x-y),abs(x-y));
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int m,q;cin>>n>>m>>q;
vector<pair<long long,long long>>v;
for(int i=0;i<m;i++){
int x;cin>>x;
v.push_back({x,x+n});
}
while(q--){
long long x,y;cin>>x>>y;
long long rs=cal(x,y);
for(auto it : v)rs=min({rs,cal(x,it.first)+cal(y,it.second)+1,cal(x,it.second)+cal(y,it.first)+1});
cout<<rs<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |