#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n, m, q;
cin>>n>>m>>q;
vector<int> bff;
int pivot = 0;
for(int i = 0; i < m; i++)
{
int a; cin>>a;
bff.push_back(a);
pivot = a;
}
//st1
//int diff = pivot;
int new_target = 0;
while(q--)
{
int x, y; cin>>x>>y;
if(y > x){
new_target = y-pivot;
}else if(y < x)
{
new_target = 2*n-(x-y);
}
//cout<<"new_target: "<<new_target<<endl;
int answer = 1e9;
//approach from centre
int center = abs(n-new_target);
int start;
if(new_target > n)
{
start = 2*n-new_target;
}
else if(new_target < n)
{
start = new_target;
}
else if(new_target == n)
{ cout<<1<<'\n'; continue;
}
answer = min(start, center+1);
cout<<answer<<'\n';
}
}
# | 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... |