AIRLINE RESTRICTIONS solution in C language.- Codechef

 

AIRLINE RESTRICTIONS

Problem Code: AIRLINE


Chef has 3 bags that she wants to take on a flight. They weigh A, B, and C kgs respectively. She wants to check-in exactly two of these bags and carry the remaining one bag with her.
The airline restrictions says that the total sum of the weights of the bags that are checked-in cannot exceed D kgs and the weight of the bag which is carried cannot exceed E kgs. Find if Chef can take all the three bags on the flight.

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • Each testcase contains a single line of input, five space separated integers A,B,C,D,E.

Output Format

For each testcase, output in a single line answer "YES" if Chef can take all the three bags with her or "NO" if she cannot.

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Constraints





Subtasks

Subtask #1 (100 points): original constraints

Sample Input 1 

3
1 1 1 15 5
8 7 6 15 5
8 5 7 15 6

Sample Output 1 

YES
NO
YES

Explanation

Test case : Chef can check-in the first and second bag (since ) and carry the third bag with her (since ).

Test case : None of the three bags can be carried in hand without violating the airport restrictions.

Test case : Chef can check-in the first and the third bag (since ) and carry the second bag with her (since ).

. . .

Solution in C.


#include <stdio.h>

int main() {
	int t;
	scanf("%d",&t);
	while(t--){
	    int a, b, c, d, e;
	    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	    if(a+b<=d && c<=e){
	        printf("YES\n");
	    }
	    else if(a+c<=d && b<=e){
	        printf("YES\n");
	    }
	    else if(b+c<=d && a<=e){
	        printf("YES\n");
	    }
	    else{
	        printf("NO\n");
	    }
	}
	return 0;
}


Try Solution On The C-Playground : https://bit.ly/3kI694q

Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C