Todays question of coke can anyone find eror,please i m stuck

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define LL long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL t;
cin>>t;
while(t–)
{
LL n,q,k,l,r;
LL p=0;
LL A[1000],B[1000],C[1000];
cin>>n>>q>>k>>l>>r;
vector <pair<int,int> > v1;
for(int i=0;i<n;i++)
{
int c,p;
cin>>c>>p;
C[i]=c;
B[i]=p;
}
for(int i=0;i<n;i++)
{

        if(C[i]>k+1)
        {
           
           A[p]=C[i]-1;
        
           p++;
        }
         if(C[i]<k-1)
        {
           
            A[p]=C[i]+1;
            
            p++;
        }
        if(C[i] >=k-1 && C[i]<=k+1)
        {
            A[p]=k;
            p++;
        }
    
    }
    int u=0;
    for(int i=1;i<=q;i++)
    {
     
        int p;
        if(C[u]>k+1)
        {
          p=A[u]-(i-1);
          
        }
        if(C[u]<k-1)
        {
        p=A[u]+(i-1);
        }
        if(C[u]>=k-1 && C[u]<=k+1)
        {
        p=A[u];
        }
        if(p>=l && p<=r)
        {
            cout<<B[u]<<" ";
        }
        else
        {
            cout<<-1<<" ";
        }
        u++;
    }
   
    cout<<"\n";
}

}

please explain code as well

first of all i take 2 array which contain temp and price and then i apply the given condition on this and store in array A after the do a loop from 1 to q and again check the condition and apply same thing by adding o=one more term "m=1 to q" .

i AM unable to find error as it is running perfect in test cases