SUMMER HEAT(COCONUT) Solution — Codechef JuneLong Challenge

Anubhav Mishra
2 min readJun 14, 2021

Problem Statement

Chefland has 2 different types of coconut, type A and type B. Type A contains only x milliliters of coconut water and type B contains only xb grams of coconut pulp. Chef’s nutritionist has advised him to consume Xa milliliters of coconut water and Xb grams of coconut pulp every week in the summer. Find the total number of coconuts (type A + type B) that Chef should buy each week to keep himself active in the hot weather.

Input

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, four integers xa, xb, Xa, Xb.

Output

For each test case, output in a single line the answer to the problem.

Constraints

  • 1≤T≤1500
  • 100≤xa≤200
  • 400≤xb≤500
  • 1000≤Xa≤1200
  • 1000≤Xb≤1500
  • xa divides Xa.
  • xb divides Xb.

Subtasks

Subtask #1 (100 points): original constraints

Sample Input

3
100 400 1000 1200
100 450 1000 1350
150 400 1200 1200

Sample Output

13
13
11

Explanation

TestCase 1: Number of coconuts of Type A required = 1000/100=10 and number of coconuts of Type B required = 1200/400=3. So the total number of coconuts required is 10+3=13.

TestCase 2: Number of coconuts of Type A required = 1000/100=10 and number of coconuts of Type B required = 1350/450=3. So the total number of coconuts required is 10+3=13.

TestCase 3: Number of coconuts of Type A required = 1200/150=8 and number of coconuts of Type B required = 1200/400=3. So the total number of coconuts required is 8+3=11.

Code (Solution)

The code has been implemented 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 sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();

System.out.println((c/a) + (d/b));
}
}
}

Hope you would have liked the article. Please give 50 claps to this article and follow me for more future programming related blogs.

References

https://www.codechef.com/JUNE21C/problems/COCONUT

(Video Editorial Link For Better Explanation)

--

--

Anubhav Mishra

Software Engineer , Having my degree B.Tech in Information Technology from BVCOE, New Delhi. Love new Technologies. Electronic Dance Music is love.