CENS20G TLE but similar code got accepted

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;

}

Never use endl with fast i/o

2 Likes

remove endl and use \n
and read this post (TLE in Help Martha(CENS20G))

1 Like

Thanks, I used \n and now it’s accepted… I wasted my lot of time on it

1 Like

endl and ‘\n’ has a vast diffrence in time complexity , for a question(large constraint) i had to use fast i/o , i realised that while using endl takes about 10 second in my compiler to run the code , but the same using ‘\n’ took around a sec

1 Like

that’s really huge