Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Marathon CodeChef Solution

Problem – Marathon CodeChef Solution

Chefland is holding a virtual marathon for the categories 10 km, 21 km and 42 km having prizes A,B,C (A<B<C) respectively to promote physical fitness. In order to claim the prize in a particular category the person must cover the total distance for that category within D days. Also a single person cannot apply in multiple categories.

Given the maximum distance d km that Chef can cover in a single day, find the maximum prize that Chef can win at the end of D days. If Chef can’t win any prize, print 0.

###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, five integers D,d,A,B,C.

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

###Constraints

  • 1≤T≤50
  • 1≤D≤10
  • 1≤d≤5
  • 1≤A<B<C≤10^5

Sample 1:

Input:
3
1 1 1 2 3
10 1 1 2 3
10 3 1 2 3
Output:
0
1
2

Explanation:

Test Case 1: The maximum distance covered by Chef is 1⋅1=1 km which is less than any of the available distance categories. Hence Chef won’t be able to claim a prize in any of the categories.

Test Case 2: The maximum distance covered by Chef is 10⋅1=10 km which is equal to distance of the first category. Hence Chef can claim the maximum prize of 1 units.

Test Case 3: The maximum distance covered by Chef is 10⋅3=30 km which is more than the distance of the second category but less than that of the third category. Hence Chef can claim the maximum prize of 2 units.

Marathon CodeChef Solution in Java

/* package codechef; // don't place package name! */

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
	{
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		
		while(t-- >0){
		    int D = in.nextInt();
		    int d = in.nextInt();
		    int a = in.nextInt();
		    int b = in.nextInt();
		    int c = in.nextInt();
		    
		    int ans = (d*D);
		    if(ans>=0 &&ans<10){
		        System.out.println(0);
		    }else if(ans<21){
		        System.out.println(a);
		    }else if (ans<42) {
		        System.out.println(b);
		    }else{
		        System.out.println(c);
		    }
		}
	}
}

Marathon CodeChef Solution in Pyth 3

test_cases = int(input(" "))

for i in range (0,test_cases):
    text = input(" ")
    (D,d,a,b,c) = map(int,text.split(" "))
    ran = D * d
    if ran >= 0 and ran < 10:
        print(0)
    elif ran < 21:
        print(a)
    elif ran < 42:
        print(b)
    else:
        print(c)


                
    

Marathon CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int D,d,A,B,C;
	    cin>>D>>d>>A>>B>>C;
	    
	    if(d*D>=42)
	    cout<<C<<endl;
	    else if(d*D>=21)
	    cout<<B<<endl;
	    else if(d*D>=10)
	    cout<<A<<endl;
	    else
	    cout<<0<<endl;
	}
	return 0;
}
Marathon CodeChef Solution Review:

In our experience, we suggest you solve this Marathon CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Marathon CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Marathon CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *