Chef On Island solution – Suppose Chef is stuck on an island and currently he has xx units of food supply 2021

Chef On Island solution

Chef On Island solution

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: Chef On Island solution

  • 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: Chef On Island solution

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 : Chef On Island solution

  • 1T3001≤T≤300
  • 1x,y1001≤x,y≤100
  • 1xr,yr,D101≤xr,yr,D≤10

Sample Input : Chef On Island solution

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

Sample Output: Chef On Island solution

YES
NO
NO

Chef On Island solution

Explanation: Chef On Island solution

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.

Chef On Island solution

Program Code: Chef On Island solution

PHP

<?php

$testCase = (int) fgets(STDIN);

while ($testCase--) {
$arr = explode(' ', fgets(STDIN));
list($x, $y, $xr, $yr, $d) = array_map("intval", $arr);
$x -= $xr * $d;
$y -= $yr * $d;
if ($x >= 0 && $y >= 0) {
echo "YES\n";
} else {
echo "NO\n";
}
}

C++

// #pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
// #define mp make_pair
#define pii pair<int,int>
// #define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
s << arr[n - 1] << "]";
return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__evars_out_var(a);
cerr << "; ";
__evars(++it, args...);
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());

for (int i = start; i < end; i++)
cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}

size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T> istream& operator >>(istream &in,vector<T> &v){
for(auto &x:v) in>>x; return in;
}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){
for(auto &x:v) out<<x<<' '; return out;
}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){
in>>p.first>>p.second; return in;
}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){
out<<p.first<<' '<<p.second; return out;
}
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
map<pair<ll,ll>, bool> vis;
ll n, m;
ll cnt = 0;
vector<string> mat;
bool isSafe(ll x, ll y)
{
if(x >= 0 && x < n && y >= 0 && y < m)
return true;
else
return false;
}
void dfs(ll x, ll y)
{
cnt++;
vis[{x, y}] = true;
// cout << x << " " << y << endl;
// cout << cnt << endl;
if(isSafe(x + 1, y) && !vis[{x + 1, y}] && mat[x + 1][y] == '1')
dfs(x + 1, y);
if(isSafe(x - 1, y) && !vis[{x - 1, y}] && mat[x - 1][y] == '1')
dfs(x - 1, y);
if(isSafe(x, y - 1) && !vis[{x, y - 1}] && mat[x][y - 1] == '1')
dfs(x, y - 1);
if(isSafe(x, y + 1) && !vis[{x, y + 1}] && mat[x][y + 1] == '1')
dfs(x, y + 1);
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
clock_t clk = clock();
int t = 1;
cin >> t;
rep(tc, t)
{
// cout << "Case #" << tc + 1 << ": ";
ll x, y, xr, yr, d;
cin >> x >> y >> xr >> yr >> d;
for(int i = 1; i <= d; i++)
{
x -= xr;
y -= yr;
} 
if(x < 0 || y < 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
} 
cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; 
}

JAVA

//Some of the methods are copied from GeeksforGeeks Website 
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{ 
static Reader sc=new Reader();
// static FastReader sc=new FastReader(System.in);

public static void main (String[] args) throws java.lang.Exception
{
try{
/*
int n=sc.nextInt();
ArrayList<Integer> al=new ArrayList<>();
ArrayList<Long> al=new ArrayList<>();
Set<Integer> set=new HashSet<>();
Collections.sort(al,Collections.reverseOrder());

long n=sc.nextLong();
for(int i=0;i<n;i++) 
String s=sc.next();
*/
int t = sc.nextInt();
while(t-->0)
{ 
long x=sc.nextLong();
long y=sc.nextLong();
long xr=sc.nextLong();
long yr=sc.nextLong();
long d=sc.nextLong();
long food=d*xr;
long water=d*yr;
if(x-food>=0 && y-water>=0)
out.println("YES");
else
out.println("NO");
}
out.flush();
out.close();
} 
catch(Exception e)
{}
}

/*
...SOLUTION ENDS HERE...........SOLUTION ENDS HERE...
*/

static void flag(boolean flag)
{
out.println(flag ? "YES" : "NO");
out.flush();
}

/* 
Map<Long,Long> map=new HashMap<>();
for(int i=0;i<n;i++)
{
if(!map.containsKey(a[i]))
map.put(a[i],1);
else
map.replace(a[i],map.get(a[i])+1);
}

Set<Map.Entry<Long,Long>> hmap=map.entrySet();
for(Map.Entry<Long,Long> data : hmap)
{

}

Iterator<Integer> it = set.iterator();
while(it.hasNext()) 
{ 
int x=it.next();
}
*/

static void print(int a[])
{
int n=a.length;
for(int i=0;i<n;i++)
{
out.print(a[i]+" ");
}
out.println();
out.flush();
}
static void print(long a[])
{
int n=a.length;
for(int i=0;i<n;i++)
{
out.print(a[i]+" ");
}
out.println();
out.flush();
} 
static void print_int(ArrayList<Integer> al)
{
int si=al.size();
for(int i=0;i<si;i++)
{
out.print(al.get(i)+" ");
}
out.println();
out.flush();
}
static void print_long(ArrayList<Long> al)
{
int si=al.size();
for(int i=0;i<si;i++)
{
out.print(al.get(i)+" ");
}
out.println();
out.flush();
}

static class Graph
{
int v;
ArrayList<Integer> list[];
Graph(int v)
{
this.v=v;
list=new ArrayList[v+1];
for(int i=1;i<=v;i++)
list[i]=new ArrayList<Integer>();
}
void addEdge(int a, int b)
{
this.list[a].add(b);
}
}
static void DFS(Graph g, boolean[] visited, int u)
{
visited[u]=true;
int v=0;
for(int i=0;i<g.list[u].size();i++)
{
v=g.list[u].get(i);
if(!visited[v])
DFS(g,visited,v);
}
} 

// static class Pair
// {
// int x,y;
// Pair(int x,int y)
// {
// this.x=x;
// this.y=y;
// }
// }

static long sum_array(int a[])
{
int n=a.length;
long sum=0;
for(int i=0;i<n;i++)
sum+=a[i];
return sum;
}
static long sum_array(long a[])
{
int n=a.length;
long sum=0;
for(int i=0;i<n;i++)
sum+=a[i];
return sum;
}

static void sort(int[] a) 
{
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long[] a) 
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}

static void reverse_array(int a[])
{
int n=a.length;
int i,t; 
for (i = 0; i < n / 2; i++) { 
t = a[i]; 
a[i] = a[n - i - 1]; 
a[n - i - 1] = t; 
} 
}
static void reverse_array(long a[])
{
int n=a.length;
int i; long t; 
for (i = 0; i < n / 2; i++) { 
t = a[i]; 
a[i] = a[n - i - 1]; 
a[n - i - 1] = t; 
} 
}

static long gcd(long a, long b) 
{ 
if (a == 0) 
return b; 

return gcd(b%a, a); 
} 
static int gcd(int a, int b) 
{ 
if (a == 0) 
return b; 

return gcd(b%a, a); 
}

static class FastReader{

byte[] buf = new byte[2048];
int index, total;
InputStream in;

FastReader(InputStream is) {
in = is;
}

int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}

String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan());
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}

int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}

long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}

static class Reader 
{ 
final private int BUFFER_SIZE = 1 << 16; 
private DataInputStream din; 
private byte[] buffer; 
private int bufferPointer, bytesRead; 

public Reader() 
{ 
din = new DataInputStream(System.in); 
buffer = new byte[BUFFER_SIZE]; 
bufferPointer = bytesRead = 0; 
} 

public Reader(String file_name) throws IOException 
{ 
din = new DataInputStream(new FileInputStream(file_name)); 
buffer = new byte[BUFFER_SIZE]; 
bufferPointer = bytesRead = 0; 
} 

public String readLine() throws IOException 
{ 
byte[] buf = new byte[64]; // line length 
int cnt = 0, c; 
while ((c = read()) != -1) 
{ 
if (c == '\n') 
break; 
buf[cnt++] = (byte) c; 
} 
return new String(buf, 0, cnt); 
} 

public int nextInt() throws IOException 
{ 
int ret = 0; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 
do
{ 
ret = ret * 10 + c - '0'; 
} while ((c = read()) >= '0' && c <= '9'); 

if (neg) 
return -ret; 
return ret; 
} 

public long nextLong() throws IOException 
{ 
long ret = 0; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 
do { 
ret = ret * 10 + c - '0'; 
} 
while ((c = read()) >= '0' && c <= '9'); 
if (neg) 
return -ret; 
return ret; 
} 

public double nextDouble() throws IOException 
{ 
double ret = 0, div = 1; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 

do { 
ret = ret * 10 + c - '0'; 
} 
while ((c = read()) >= '0' && c <= '9'); 

if (c == '.') 
{ 
while ((c = read()) >= '0' && c <= '9') 
{ 
ret += (c - '0') / (div *= 10); 
} 
} 

if (neg) 
return -ret; 
return ret; 
} 

private void fillBuffer() throws IOException 
{ 
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
if (bytesRead == -1) 
buffer[0] = -1; 
} 

private byte read() throws IOException 
{ 
if (bufferPointer == bytesRead) 
fillBuffer(); 
return buffer[bufferPointer++]; 
} 

public void close() throws IOException 
{ 
if (din == null) 
return; 
din.close(); 
} 
}
static PrintWriter out=new PrintWriter(System.out);
static int int_max=Integer.MAX_VALUE;
static int int_min=Integer.MIN_VALUE;
static long long_max=Long.MAX_VALUE;
static long long_min=Long.MIN_VALUE;
}
// Thank You !

PYTHON 

t=int(input())
for _ in range(t):
x,y,xr,yr,d=map(int,input().split())
a=x//xr
b=y//yr
if(min(a,b)>=d):
print("Yes")
else:
print("No")

Also read : Flower Sequence solution codechef 2021

Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution, Chef On Island solution,


Chef On Island solution

Leave a Comment