BFRIEND WA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s =new Scanner(System.in);
		int t=s.nextInt();
		while(t--!=0)
		{
		    long n=s.nextLong();
		    long a=s.nextLong();
		    long b=s.nextLong();
		    long c=s.nextLong();
		    long ans=0,total=Long.MAX_VALUE;
		    for(long i=0;i<n;i++)
		    {
		        long temp=s.nextLong();
		        if(temp>a && temp <b || temp<a && temp >b)
		        {
		         total=Math.abs(a-b)+c;
		         break;
		        }
		        else if(temp>a && temp>b && a<b)
		        {ans=2*(temp-b)+Math.abs(a-b)+c;
		         if(ans<total)
		         total=ans;
		            
		        }
		        else if(temp>a && temp>b && a>b)
		        {ans=2*(temp-a)+Math.abs(a-b)+c;
		         if(ans<total)
		         total=ans;
		            
		        }
		   
		        else if(temp<a && temp<b && a<b)
		        {ans=(2*(a-temp))+Math.abs(a-b)+c;
		        //System.out.println(ans);
		         if(ans<total)
		         total=ans;
		            
		        }
		        else if(temp<a && temp<b && a>b)
		        {ans=(2*(b-temp))+Math.abs(a-b)+c;
		        //System.out.println(ans);
		         if(ans<total)
		         total=ans;
		            
		        }
		    }
		    System.out.println(total);
		     
		}
	}
}

I have tried all the possible test cases but still i get WA. please help me

Try this test case :
1
7 9 1 1
2 3 4 5 6 7 8

Reply the output

1 Like

Thanks for the reply. I get the output as 9. Is it correct?

Yepp…its correct

1 Like

Thanks for the reply. My bad is that I still dont get AC for solution. Do you have any other Testcase? Can you suggest me some if you have? Thanks

Why do you keep total as an extra variable!?.. Its utilising just extra space in memory which is unnecessary…

And also instead of writing all these multiple cases … just form 2 cases :

  1. If a friend lies in between bob and alice’s floor ( your if condition)
  2. A general case if case1 is not satisfied
1 Like

hey! thanks for the idea. will look into it. btw keeping extra variable leads to wa?

Nope… But its just waste of memory

@raksha1906 test cases will help him guide where he is wrong ! Not multiple but 2 or 3 test cases will be enough to figure out where he is wrong !

1 Like

Thank you for the reply. Can you please be more clear? If the test case gives correct answer then isn’t my logic right?

What do you mean by

??

Consider the testcase:

1
7 23 26 84
69 26 47 14 36 14 3
1 Like

Can the friend and the point where Bob is initially placed be equal?

1 Like

I only scanned the Problem Statement briefly, but didn’t see anything that suggested otherwise.

1 Like

Such a genius you are! When the values are same… then the answer changes.

2 Likes

But it’s not mentioned that same floor can occur

It’s not mentioned that it can’t :slight_smile:

2 Likes