CHEF_CAKE - Editorial

PROBLEM LINK:

Contest

Setter: chayan_d
Tester: debrc , mishra_roshan
Editorialist: chayan_d

DIFFICULTY:

Easy

PREREQUISITES:

Basic observations

PROBLEM:

Arpita’s favorite cake shop is Pâtisserie du chef. Pâtisserie du chef sells cakes of three sizes: small cake weighting 1 pound that can be divided into 6 pieces, medium ones weighting 2 pounds can be divided into 8 pieces, and large cake weighting 3 pounds can be divided into 10 pieces. Baking them takes 15, 20 and 25 minutes, respectively.

Today is Arpita’s birthday, and N number of her friends will come, so she decided to place an order from her favorite cake shop. Arpita wants to order so much cake that each of his friends gets atleast one piece of cake.

Note: Arpita can order more than one cake if needed.

The cooking time of the order is the total baking time of all the cakes in the order.

Your task is to determine the minimum number of minutes that is needed to bake cake containing atleast N pieces in total.

EXPLANATION

Since N number of friends will come , therefore we need atleast N pieces of cake.
We are given that small, medium and large cake have 6, 8,10 pieces respectively.

if N is less than or qual to 6, then we have to order 1 small sized cake
if N is equal to 8, then we have to order 1 medium sized cake.
if N is equal to 10, then we have to order 1 large sized cake.
if N is equal to 12, then we have to order 2 small sized cake.
if N is equal to 14, then we have to order 1 small sized cake and 1 medium sized cake.
and so on…

We can make an observation that every even number greater than 6 can be formed as a combination of 6, 8, 10.

If N is odd, then we will increase it by 1 (since the cake is cooked only with an even number of pieces)

Note: that the “speed” of cooking 1 piece of cake is the same for all sizes — 1 piece of cake for 2.5 minutes.

This means that for any N there will be a set of cakes with exactly N pieces.
Then the answer is N∗2.5 (in the solution, it is better to use the formula N/2∗5).

SOLUTIONS:

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

using namespace std;

int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    cout << max<long long int>(6,n+1)/2*5<< '\n';
  }
}
Tester's Solution
Java
import java.util.*;
public class Main {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	
	    while(t-->0){
        long n=sc.nextLong();
        System.out.println(((Math.max(6,n+1))/2)*5);
    }
	}
}

python
for _ in range(int(input())):
    print(max(6,int(input())+1)//2*5)

Feel free to Share your approach.

Suggestions are welcomed as always had been.