Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Car Range CodeChef Solution

Problem – Car Range CodeChef Solution

The fuel economy of a car is the distance which it can travel on one litre of fuel.

The base fuel economy (i.e, its fuel economy when there is only one person – the driver – in the car) of a certain car is M kilometres per litre. It was also observed that every extra passenger in the car decreases the fuel economy by 1 kilometre per litre.

P people want to take this car for a journey. They know that the car currently has V litres of fuel in its tank.

What is the maximum distance this car can travel under the given conditions, assuming that all P people always stay in the car and no refuelling can be done?

Note that among the P people is also a driver, i.e, there are exactly P people in the car.

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of a single line of input, containing three space-separated integers P,M, and V – the number of people, base fuel economy, and amount of fuel present in the car, respectively.

Output Format

For each test case, output a single line containing one integer – the maximum distance that the car can travel.


  • 1≤T≤3⋅10^4
  • 1≤P≤5
  • 6≤M≤56
  • 1≤V≤100

Sample 1:

5 10 20
1 6 10
4 6 1


Test Case 1: There are 5 people in the car, and its base fuel economy is 10. Thus, its effective fuel economy is 10−4=6, since there are 4 people present other than the driver. There are 20 litres of fuel in the car, so the maximum distance that can be travelled is 6⋅20=120.

Test Case 2: The effective fuel economy is 6, and the maximum distance that can be travelled is 6⋅10=60.

Test Case 3: The effective fuel economy is 3, and the maximum distance that can be travelled is 3⋅1=3.

Car Range CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	int t;
	    int p,m,v;
	    else cout<<(m-p+1)*v<<endl;
	return 0;

Car Range CodeChef Solution in Java

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

import java.util.*;
import java.lang.*;

/* 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(;
		int t=sc.nextInt();
		    int p=sc.nextInt();
		    int m=sc.nextInt();
		    int v=sc.nextInt();
		    else System.out.println((m-p+1)*v);

Car Range CodeChef Solution in Pyth 3

# cook your dish here
for i in range(int(input())):
    if p==1:
Car Range CodeChef Solution Review:

In our experience, we suggest you solve this Car Range 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 Car Range CodeChef Solution

Find on CodeChef


I hope this Car Range 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 *