Help me in solving CHFSPL problem

My issue

Could someone offer me assistance with solving this problem?

My code

#include <stdio.h>

int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++)
	{
	    int a,b,c,s1,s2,s3;
	    scanf("%d%d%d",&a,&b,&c);
	    s1=a+b;
	    s2=b+c;
	    s3=c+a;
	        if(s1>s2 && s1>s3)
	        {
	            printf("%d\n",s1);
	        }
	        else if(s2>s1 && s2>s3)
	        {
	            printf("%d\n",s2);
	        }
	        else
	        {
	            printf("%d\n",s3);
	        }
	}
	return 0;
}


Problem Link: CodeChef: Practical coding for everyone

@nitheesha39
In the given problem, we need to find the largest two numbers and print their sum.

In your code, you are just finding and printing the largest element.

To reach the proper solution, you could either;

  • Find the smallest element and subtract it from sum of all three

or,

  • Find the two largest elements and print their sum

Here is my code in Python for reference;

# cook your dish here
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    print((a+b+c)-min(a,b,c))
    

Here, I am subtracting the lowest element from sum of all three.

@codechief1
I attempted to apply the same logic, but my test cases continue to fail.

include <stdio.h>
int min_ele(int a,int b,int c)
{
int min=a;
if(b<a)
{
min=b;
}
else if(c<a)
{
min=c;
}
else
{
min=a;
}
return min;
}
int main(void) {
// your code goes here
int t;
scanf(“%d”,&t);
for(int i=0;i<t;i++)
{
int a,b,c;
scanf(“%d%d%d”,&a,&b,&c);
printf(“%d\n”,(a+b+c)-(min_ele(a,b,c)));
}
return 0;
}

@nitheesha39 The condition for checking minimum is not correct.

Let’s take the following case;
a=10, b=7, c=2

Following your code logic, it will show b as minimum and wont even check for c.

Taking the first code, by altering some inequalities we can get desired result.

int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++)
	{
	    int s1,s2,s3;
	    scanf("%d%d%d",&s1,&s2,&s3);
	        if(s1<=s2 && s1<=s3)
	        {
	            printf("%d\n",(s2+s3));
	        }
	        else if(s2<=s1 && s2<=s3)
	        {
	            printf("%d\n",(s1+s3));
	        }
	        else
	        {
	            printf("%d\n",(s1+s2));
	        }
	}
	return 0;
}

This code should work.

Here, we are finding the least one and printing the sum of other two.

This code will fail some of the test cases .First find out the smallest of three number and then add the rest two numbers.