CLPNT EDITORIAL

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

hello brother,
fixed error modified code with comments
let me know if anything is unclear @anon56550829

1 Like

I used a similar way but got a wrong answer, please help here’s my solution.
https://www.codechef.com/viewsolution/35669865
@souradeep1999 @faisal1947 @jyoti369

thank you so much,
just one question that is why do i get O[n*2] when I used elif when checking x+y in wall

im glad it helped @tn6541
x+y in wall: is O(N) time (linear search in list internally)
and this is inside loop which runs q times hence it becomes O(q*N)
thats why i made a set of all a’s elements ,x+y in set is O(1)

1 Like

when you declare a local variable it is stored in the stack memory
Global variables are stored in heap memory.Online compilers mai often there is a limit of stack memory.Heap memory limit is large.

So to search an elements in a set is faster than in a list?