CLPNT EDITORIAL

solved the problem but instead of using binary searching i used linear like an idiot. Feelsbadman

Read the constraints, you don’t have to sort the vector.

Cool, I didn’t observe that

Yes , you are are getting TLE since For loop on Line number 36 , since in WORST time it is taking O(n ) for every Query so , we need to reduce it to O(log(n)) which can be done using Binary Search → refer my solution :slight_smile:CodeChef: Practical coding for everyone
(PS: i have used LOWER_BOUND Function which is similar to binary search )
std::upper_bound and std::lower_bound for Vector in C++ STL - GeeksforGeeks
this might help

thanks to the organiser ,nice problems indeed, @souradeep1999

question
got stuck in figuring out why i got TLE even if i implemented in required time complexity.
when i used python3 built in method for bs it got accepted code
but i implemented bs myself it show TLE TLE code ,
if any one can point out error i would be glad.
@jyoti369 @aadiupadhyay @cubefreak777 @jojo9910 @sampras123
thanks a ton in advance

1 Like

there is a difference between if (a=b) and if (a==b)

see there is one small difference in your code. Obviously first one gives WA since equality is done through ==.

Okay… I have copied your code in my editor and made a slight change between line no. 30 to 34
& got an AC code. Here is the link : CodeChef: Practical coding for everyone
It will not cost any overflow due to line no. 30 , therefore , WA/TLE verdict.
Hope this helps. THANKS !!!

1 Like

Easy approach :+1::+1:

Thank you for pointing it out.

@jyoti369 thanks a lot buddy >
thanks for entertaining stupid error of stupid guy (me).
my mistakes
i+=1 instead of i=mid+1
j-=1 instead of j=mid-1
thanks again

I used a similar approach but got a wrong answer, here’s my solution CodeChef: Practical coding for everyone

please help

most welcome !

1 Like

I am finding lower bound for each x+y on walls and if x+y is equal to value if wall it is -1 else it is the index , my solution is giving WA can somebody help
my solution

https://www.codechef.com/viewsolution/35672769
This is my Code I am new cannot understand whats wrong.
Also I am getting TLE error
can someone correct

same logic but used lower_bound stl (even tried upper_bound) but got WA?
any idea how??

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin>>t;
while(t–)
{
long long int n,a;
cin>>n;
vector arr;
for(long long i=0;i<n;i++)
{
cin>>a;
arr.push_back(a);
}
long long int q;
cin>>q;
while(q–)
{
long long int x,y,res=0,flag=0;
cin>>x>>y;
if(x==0 && y==0)
res=0;
else
{
auto itr=lower_bound(arr.begin(),arr.end(),(x+y))-arr.begin();
//cout<<“itr=”<<itr<<endl;
if(arr[itr]==(x+y))
flag=1;
else
res=itr;
}
if(flag==1)
cout<<"-1\n";
else
cout<<res<<"\n";
}
}
return 0;
}

https://www.codechef.com/viewsolution/35700782
Can anyone see why my B Search approach is getting TLE?

1 Like

Can someone tell me why am i getting WA.
https://www.codechef.com/viewsolution/35658188

https://www.codechef.com/viewsolution/35660483
@souradeep1999
Can you provide an example for the above solution, so i can understand why it was failing? Thanks!

Same with me I applied leastgreatest

hey fixed ur code a , commented for better understanding
link
u committed ; ss=x+y not max(x,y)
let me know if u have querry @soumya_2882