[SOLUTION] Lifeline solution codechef 2021 – Code Cracker codechef

Lifeline solution codechef 2021 – Code Cracker

Lifeline solution codechef 2021

Chef has been tested for Covid positive. He is AA years old. He has to be admitted to the covid hospital. There are NN beds in the hospital.

There is a chart which shows the no. of days in which a particular age group gets cured.

Age group Days to recover No. of patients
0-18(child) 10 x
19-50(adult) 14 y
51+(old) 21 z

Chef wants to know whether he could be saved if he gets admitted to the covid hospital. He could be admitted only when a bed is vacant.

The chef has only dd days left to get saved. Find whether he could be saved or not!

Lifeline solution codechef 2021

Input: Lifeline solution codechef 2021

  • The first line of the input contains a single integer TT — the number of test cases in the given input. Then follow TT descriptions of individual tests.
  • The first line of each test case contains three space-separated integers, A,N,dA,N,d — their age, no. of beds, and days left to be cured respectively.
  • The second line contains three space-separated integers x,y,zx,y,z.

Output: Lifeline solution codechef 2021

  • Output in a single line, the answer, which should be “YES” if Chef gets admitted and “NO” if not.

Constraints Lifeline solution codechef 2021

  • 1T1001≤T≤100
  • 1A1001≤A≤100
  • 0<N10000<N≤1000
  • 10d<5010≤d<50
  • 0x+y+zN0≤x+y+z≤N

Sample Input: Lifeline solution codechef 2021

2
15 18 26
2 8 8
88 65 33
0 55 10

Sample Output: Lifeline solution codechef 2021

YES
NO

Lifeline solution codechef 2021

EXPLANATION:Lifeline solution codechef 2021

  • In the first test case, There are 26 days for the chef to cure. After 10 days, a child gets discharged and 1 bed will be vacant. Since 16 days are still left for the chef to be cured, he needs only 10 days to recover. So he’ll be cured.
  • In the second test case, the bed will be vacant after 14 days when an adult will get discharged. So there were only 19 days left for the chef to be cured. As he is 88 years old he needs 21 days to recover. That’s why the chef could not be saved.

Problem Code :Lifeline solution codechef 2021

C++

#include <iostream>
using namespace std;

int main() {
// your code goes here
int test;
cin>>test;
while(test--){
int age,N,d;
cin>>age>>N>>d;
int x,y,z;
cin>>x>>y>>z;
if((x+y+z)<N){
int recover=0;
if(age<=18)recover=10;
else if(age<=50)recover=14;
else recover=21;

if(d>=recover){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
continue;
}
int vacant=0;
if(x!=0)vacant=10;
else if(y!=0)vacant=14;
else vacant=21;

d=d-vacant;

int recover=0;
if(age<=18)recover=10;
else if(age<=50)recover=14;
else recover=21;

if(d>=recover){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
Python ( correct the indentation ) 

try:
for t in range(int(input())):
a1,n,d1=map(int,input().split())
x1,y,z1=map(int,input().split())
if(0<=a1<=18):
if((x1+y+z1)<n):
if(d1>=10):
print("YES")
else:
print("NO")
else:
if(x1!=0):
c=d1-10
if(c>=10):
print("YES")
else:
print("NO")
elif(y!=0):
c=d1-14 
if(c>=10):
print("YES")
else:
print("NO")
else:
if(z1!=0):
c=d1-21 
if(c>=10):
print("YES")
else:
print("NO")



elif(19<=a1<=50):
if((x1+y+z1)<n):
if(d1>=14):
print("YES")
else:
print("NO")
else:
if(x1!=0):
c=d1-10
if(c>=14):
print("YES")
else:
print("NO")
elif(y!=0):
c=d1-14 
if(c>=14):
print("YES")
else:
print("NO")
else:
if(z1!=0):
c=d1-21 
if(c>=14):
print("YES")
else:
print("NO")


else:
if(a1>=51):
if((x1+y+z1)<n):
if(d1>=21):
print("YES")
else:
print("NO")
else:
if(x1!=0):
c=d1-10
if(c>=21):
print("YES")
else:
print("NO")
elif(y!=0):
c=d1-14 
if(c>=21):
print("YES")
else:
print("NO")
else:
if(z1!=0):
c=d1-21 
if(c>=21):
print("YES")
else:
print("NO")


except:
pass
Java

import java.io.*;
import java.util.*;

class LF00 {
FastReader fr = new FastReader();
StringBuilder sb = new StringBuilder();
final int mod = 1_000_000_007;
final int maxn = 1_000_007;

public void run() {
int tt=fr.nextInt();
while(tt-->0){
int A=fr.nextInt();
int N=fr.nextInt();
int d = fr.nextInt();
int x=fr.nextInt();
int y=fr.nextInt();
int z = fr.nextInt();
if(x+y+z<N){
if(A>=0 && A<=18){
if(d>=10){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
else if(A>=19 && A<=50){
if(d>=14){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
else{
if(d>=21){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
}
else{
if(x!=0){
d-=10;
}
else{
if(y!=0){
d-=14;
}
else{
d-=21;
}
}
if(A>=0 && A<=18){
if(d>=10){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
else if(A>=19 && A<=50){
if(d>=14){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
else{
if(d>=21){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
}
}
System.out.println(sb);
}

public void reverse(int[] a) {
for (int i = 0, j = a.length - 1; i <= j; i++, j--) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}

public void sort(int[] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
int temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr);
}

public void sort(long[] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
long temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr);
}

public static void main(String[] args) {
new LF00().run();
}

//Fast I/O
static class FastReader {
BufferedReader br;
StringTokenizer st;

public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
st = null;
}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException ie) {
System.out.println(ie);
}
}
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 ie) {
System.out.println(ie);
}
return str;
}
}
}

Also read : Flower Sequence solution codechef 2021

Leave a Comment