CCISLAND - Editorial

PROBLEM LINK:

Practice
Contest: Division 3
Contest: Division 2
Contest: Division 1

Author: Daanish Mahajan
Tester: Felipe Mota
Editorialist: Vichitr Gandas

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Given x units of food and y units of water. You need x_r units of food and y_r units of water per day to work. If it takes D days to finish the work, would you be able to finish it with given amount of food and water?

EXPLANATION:

Just check the condition as specified in the statement. If it takes D days to finish the work, and x_r units of food and y_r units of water are needed per day. Hence total of D \cdot x_r units of food and D \cdot y_r units of water are needed. Check if they are less than or equal to available amount ie check if D \cdot x_r \leq x and D \cdot y_r \leq y.

TIME COMPLEXITY:

O(1) per test case

SOLUTIONS:

Setter's Solution
#include<bits/stdc++.h>

# define pb push_back 
#define pii pair<int, int>
#define mp make_pair
# define ll long long int

using namespace std;
  
const int maxt = 300, minv = 1, maxv = 10, mintv = 1, maxtv = 100;
const string newln = "\n", space = " ";

int main()
{   
    int t; cin >> t;
    while(t--){
        int x, y, xr, yr, d; cin >> x >> y >> xr >> yr >> d;
        string ans = (min(x / xr, y / yr) >= d ? "YeS" : "No");
        cout << ans << endl;
    }
} 
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
long long readInt(long long l,long long r,char endd){
	long long x=0;
	int cnt=0;
	int fi=-1;
	bool is_neg=false;
	while(true){
		char g=getchar();
		if(g=='-'){
			assert(fi==-1);
			is_neg=true;
			continue;
		}
		if('0'<=g && g<='9'){
			x*=10;
			x+=g-'0';
			if(cnt==0){
				fi=g-'0';
			}
			cnt++;
			assert(fi!=0 || cnt==1);
			assert(fi!=0 || is_neg==false);
 
			assert(!(cnt>19 || ( cnt==19 && fi>1) ));
		} else if(g==endd){
			if(is_neg){
				x= -x;
			}
			assert(l<=x && x<=r);
			return x;
		} else {
			assert(false);
		}
	}
}
string readString(int l,int r,char endd){
	string ret="";
	int cnt=0;
	while(true){
		char g=getchar();
		assert(g!=-1);
		if(g==endd){
			break;
		}
		cnt++;
		ret+=g;
	}
	assert(l<=cnt && cnt<=r);
	return ret;
}
long long readIntSp(long long l,long long r){
	return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
	return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
	return readString(l,r,'\n');
}
string readStringSp(int l,int r){
	return readString(l,r,' ');
}
long long TEN(int p){ long long r = 1; while(p--) r *= 10; return r; }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = readIntLn(1, 300);
	while(t--){
		int x = readIntSp(1, 100);
		int y = readIntSp(1, 100);
		int xr = readIntSp(1, 10);
		int yr = readIntSp(1, 10);
		int d = readIntLn(1, 10);
		for(int i = 0; i < d && x >= 0 && y >= 0; i++)
			x -= xr, y -= yr;
		cout << (x >= 0 && y >= 0 ? "YES\n" : "NO\n");
	}
	return 0;
}
Editorialist's Solution
/***************************************************

@author: vichitr
Compiled On: 23 Apr 2021

*****************************************************/
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int x, y, xr, yr, d;
    cin >> x >> y >> xr >> yr >> d;
    if(xr * d <= x and yr * d <= y)
        cout <<"YES\n";
    else
        cout <<"NO\n";
}

signed main()
{
    int t = 1;
    cin >> t;
    for(int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}

Please check my solution. Why this is giving WA?? But when I manually input test cases it works correct.
import java.util.Scanner;
class Codechef
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(); sc.nextLine();
for(int i=0;i<n;i++){
String []s=sc.nextLine().split(" ");
int aa[]=new int[s.length];
for(int j=0;j<s.length;j++){
aa[j]=Integer.parseInt(s[j]);
}
if(((aa[2]*aa[4]) < aa[0]) &&((aa[3]*aa[4])< aa[1])){
System.out.println(“Yes”);

	    }
	    else{
	        System.out.println("No");
	    }
	}
}

}