CLPNT EDITORIAL

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?

yup… @anon56550829 its O(1) unlike list which is O(N)

1 Like

https://www.codechef.com/viewsolution/35674052

This is my solution approach. Please help to find error in the code, I am getting wrong answer.

bro @pranava23 could not understand ur approach,
will u plz let me know how did u approached because its certainly not similar to anyone approach i have seen and debug so far.
thank you.

brother @tech_29
i don’t know java much but i tried to debug:
portion of your code:

     while(q>0){
    		        int x = sc.nextInt();
    		        int y = sc.nextInt();
    		        
    		        int result = 0;
    		        for(int i=0;i<n;i++){
    		            if((x+y)==a[i]){
    		                result = -1;
    		                break;
    		            }      
    		        }
    		        if(result==0){
    		            for(int i=0;i<n;i++){
    		            if(a[i]>x && a[i]>y)
    		                break;
    		            else 
    		                result++;
    		            }      
    		        }

error in line 32(of ur submitted code)
if(a[i]>x && a[i]>y) should be if (a[i]>x+y):
after also after loop check
if a[i]>x+y:
print i+1
else:
print(i)

anyways:
no need two separated for loops both can be done in single loop
moreover:
even if u rectify mistakes u would get TLE since for overall complexity would become (q*N) use BS instead of for loop

please let me know if anything is unclear
hope this helps

Try upper_bound() -1
When you use lower_bound it gives you one greater index of the element lower Or exact. So, if your element is at n-1 position it will return n.
In upper_bound-1.
If index == -1
Cout<< 0
Else if (v[index] == x+y)
Cout<<-1;
Else
Cout<< index+1
You will get correct answer hope you get it :slight_smile:

why WA is coming when used lower_bound function
Please tell where I’m wrong … :pleading_face: :pleading_face:

  1. Found the min distance of the line from the origin which is the length of the normal.
    For q queries I checked
  2. Used the equation y=(-x) + c to check if it lies on the line
  3. Then found the distance of the given point, from origin which I compared to the arr containing distances
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t>0){
	    t--;
	    int n;
	    cin>>n;
	    vector<long> a;
	    long temp;
	    for(long i =0;i<n;i++){
	        cin>>temp;
	        a.push_back(temp);
	    }
	    //sort(a.begin(),a.end());
	    long q;
	    cin>>q;
	    long ans = 0;
	    long x=0,y=0;
	    auto it = a.begin();
	    for(long i=0;i<q;i++){
	        cin>>x>>y;
	        it = lower_bound(a.begin(),a.end(),x+y);
	        if(*it == x+y)
	            cout<<-1<<endl;
	        else{
	            ans = (it - a.begin());
	            /*
	                  if(it == a.end() || *it < x+y)
	                       ans = n;
	                  if(ans > n)
	                       ans = n;
	                  if(ans < 0 || it == a.begin())
	                       ans = 0;
	           */
	            cout<<ans<<endl;
	        }
	    }
	}
	return 0;
}

I can’t see why i am getting WA here…
help!

https://www.codechef.com/viewsolution/35730710
@faisal1947 Can you help me out with this question, I got the correct answer for the sample test case but when I submitted I got RUNTIME error

I have done similarly. I am still getting TLE. Can anyone please help me?https://www.codechef.com/viewsolution/35732644