Codechef September long challenge 2021 | Airline Restrictions Solution

 

Codechef September long challenge 2021 | Airline Restrictions Solution


Chef has 33 bags that she wants to take on a flight. They weigh AABB, and CC 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 DD kgs and the weight of the bag which is carried cannot exceed EE 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 TT denoting the number of test cases. The description of TT test cases follows.
  • Each testcase contains a single line of input, five space separated integers A,B,C,D,EA,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

  • 1T360001≤T≤36000
  • 1A,B,C101≤A,B,C≤10
  • 15D2015≤D≤20
  • 5E105≤E≤10

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 11: Chef can check-in the first and second bag (since 1+1=2151+1=2≤15) and carry the third bag with her (since 151≤5).

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

Test case 33: Chef can check-in the first and the third bag (since 8+7158+7≤15) and carry the second bag with her (since 565≤6).


C++ Solution

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
if ((a + b <= d) && (c <= e))
cout << "YES" << endl;
else if ((b + c <= d) && (a <= e))
cout << "YES" << endl;
else if ((c + a <= d) && (b <= e))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}

Java Solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0)
{
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
boolean flag = false;
if(a+b<=d && c<=e)
flag = true;
if(b+c<=d && a<=e)
flag = true;
if(a+c<=d && b<=e)
flag = true;
if(flag == true)
System.out.println("YES");
else
System.out.println("NO");
}
}
}

 

Post a Comment

Previous Post Next Post