Chef On Island Codechef Solution

Hello Programmers In this post, you will know how to solve the Chef On Island Codechef Solution.

Ezoicreport this adChef On Island Codechef Solution
Chef On Island Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Suppose Chef is stuck on an island and currently he has xx units of food supply and yy units of water supply in total that he could collect from the island. He needs xrxr units of food supply and yryr units of water supply per day at the minimal to have sufficient energy to build a boat from the woods and also to live for another day. Assuming it takes exactly DD days to build the boat and reach the shore, tell whether Chef has the sufficient amount of supplies to be able to reach the shore by building the boat?

Input:

  • First line will contain TT, number of testcases. Then the testcases follow.
  • Each testcase contains of a single line of input, five integers x,y,xr,yr,Dx,y,xr,yr,D.

Output:

For each testcase, output in a single line answer “YES” if Chef can reach the shore by building the boat and “NO” if not (without quotes).

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

Constraints

  • 1≤T≤3001≤T≤300
  • 1≤x,y≤1001≤x,y≤100
  • 1≤xr,yr,D≤101≤xr,yr,D≤10

Sample Input

3
4 2 1 1 1
4 2 1 3 1
4 2 4 2 2

Sample Output:

YES
NO
NO

Explanation:

TestCase 1: Chef’s food supply will last for 41=441=4 days and water supply will last for 21=221=2 days, so in total he will be able to survive for min(4,2)=2min(4,2)=2 days and since required time to reach the shore is 11 day, he will be able to reach there.

TestCase 2: Chef’s food supply will last for 41=441=4 days and water supply will last for 23=0.6723=0.67 days, so in total he will be able to survive for min(4,0.67)=0.67min(4,0.67)=0.67 days and since required time to reach the shore is 11 day, he won’t be able to reach there.

TestCase 3: Chef’s food supply will last for 44=144=1 day and water supply will also last for 22=122=1 day, so in total he will be able to survive for min(1,1)=1min(1,1)=1 day and since required time to reach the shore is 22 days, he won’t be able to reach there.

Ezoicreport this adChef On Island CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
/* 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
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int T=in.nextInt();
		int L,good=0,bad=0,flag=0;
		char c;
		String s;
		while(T>0)
		{
		    T--;
		    L=in.nextInt();
		    s=in.next();
		    for(int y=0;y<s.length();y++)
		    {
		        c=s.charAt(y);
		        if(c=='1')
		        {
		            good++;
		        }
		        else
		        {
		            bad++;
		        }
		        if(good>=bad)
		        {
		            System.out.println("YES");
		            flag=100;
		            break;
		        }
		    }
		    if(flag!=100)
		    {
		        System.out.println("NO");
		    }
		    flag=0;good=0;bad=0;L=0;
		}
	}
}
Ezoicreport this ad

Chef On Island CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t--){
	    int l;
	    cin>>l;
	    string s;
	    cin>>s;
	    int g=0;
	    int zero=0,one=0;
	    for(int i=0;i<l;i++){
	        if(s[i]=='0'){
	            zero++;
	        }else{
	            one++;
	        }
	            if(one>=zero){
	                g=1;
	                cout<<"YES\n";
	                break;
	            }
	    }
	    if(g==1){
	    }else{
	        cout<<"NO"<<endl;
	    }
	}
	return 0;
}

Chef On Island CodeChef Solution in Python

for _ in range(int(input())):
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    l.sort()
    ans=[]
    for i in range(k-1,n):
        ans.append(l[i]-l[i-(k-1)])
    print(min(ans))

Disclaimer: The above Problem (Chef On Island) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Multiple of 3 CodeChef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad