I can’t figure out why this code is getting TLE for CENS20G but others similar code get accepted.
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
lli l,r,u,d,x1,x2,y1,y2,c;
while(t--){
string s;
cin>>s;
l=r=u=d=0;
for(int i = 0; i<s.length(); i++){
if(s[i]=='R')r++;
else if(s[i]=='L')l++;
else if(s[i]=='U')u++;
else d++;
}
cin>>x1>>y1>>c;
while(c--){
cin>>x2>>y2;
x2 -= x1;
y2 -= y1;
if(x2<0 && l<-x2)cout<<"NO";
else if(x2>0 && r<x2)cout<<"NO";
else if(y2<0 && d<-y2)cout<<"NO";
else if(y2>0 && u<y2)cout<<"NO";
else{
cout<<"YES "<<abs(x2)+abs(y2);
}
cout<<endl;
}
}
return 0;
}