Which Fuel is Cheaper CodeChef Solution

Hello Programmers In this post, you will know how to solve the Which Fuel is Cheaper CodeChef solution. Which is a part of CodeChef Solutions.

Which Fuel is Cheaper CodeChef Solution
Which Fuel is Cheaper CodeChef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

The current price of petrol is X rupees, and the current price of diesel is Y rupees. At the start of each month, the price of petrol increases by A rupees and the price of diesel increases by B rupees. Chef is curious to know which fuel costs less at the end of the Kth month. If petrol is cheaper than diesel at the end of Kth month, then print PETROL. If diesel is cheaper than petrol at the end of the Kth month, then print DIESEL. If both the fuels have the same price at the end of the Kth month, then print SAME PRICE.

Input

  • 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 five space-separated integers X, Y, A, B, K.

Output

For each test case,

  • Print PETROL if petrol is cheaper than diesel.
  • Print DIESEL if diesel is cheaper than petrol.
  • Print SAME PRlCE otherwise.

Note: The output is case-insensitive. You can print each character in either lower-case or upper-case.

Constraints

  • 1 ≤ T ≤ 1000
  • 1 ≤ K ≤ 1000
  • 0 ≤ X, Y, A, B ≤ 1000

Subtasks

Subtask 1 (100 points): Original constraints

Example

Input:
3
1 1 1 1 1
2 1 2 1 2
2 2 1 1 2
Output:
SAME PRICE
DIESEL
SAME PRICE

Explanation

Test case 1:

Initially, the price of petrol is 1 rupee and the price of diesel is rupee. Since A = 1 and B = 1, the prices of both petrol and diesel increase by 1 rupee at the start of every month. So, at the start of the first month, the price of petrol becomes 1 + 1 = 2 rupees and the price of diesel becomes 1 + 1 = 2 rupees. By the end of the first month, the price of petrol and diesel are both 2 rupees and hence they both have the same price.

Test case 2:

Initially, the price of petrol is 2 rupees and the price of diesel is 1 rupee. Since A = 2 and B = 1, the price of petrol increases by 2 rupee and the price of diesel increases by 1 rupee at the start of every month. It follows that at the start of the first month, the price of petrol becomes 2 + 2 = 4 rupees and the price of diesel becomes 1 + 1 = 2 rupees. And by the start of the second month, the price of petrol becomes 4 + 2 = 6 rupees and the price of diesel becomes 2 + 1 = 3 rupees. By the end of the second month, the prices of petrol and diesel are 6 rupees and 3 rupees respectively and hence diesel is cheaper than petrol.

Test case 3:

Initially, the price of petrol is 2 rupee and the price of diesel is 2 rupee. Since A = 1 and B = 1, the price of petrol increases by rupee and the price of diesel increases by 1 rupee at the start of every month. It follows that at the start of the first month, the price of petrol becomes 2 + 1 = 3 rupees and the price of diesel becomes 2 + 1 = 3 rupees. And by the start of the second month, the price of petrol becomes 3 + 1 = 4 rupees and the price of diesel becomes 3 + 1 = 4 rupees. By the end of the second month, the prices of petrol and diesel are both 4 rupees and hence both have the same prices.

Which Fuel is Cheaper CodeChef Solution in JAVA

/* package codechef; // don't place package name! */
import java.util.Scanner;
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 input = new Scanner(System.in);
        int test = input.nextInt();
        while (test > 0){
            int X = input.nextInt();
            int Y = input.nextInt();
            int A = input.nextInt();
            int B = input.nextInt();
            int K = input.nextInt();
            int petrol_price = X + (A * K);
            int diesel_price = Y + (B * K);
            if (petrol_price < diesel_price){
                System.out.println("PETROL");
            }
            else if (diesel_price < petrol_price){
                System.out.println("DIESEL");
            }
            else{#Which Fuel is Cheaper | CodeChef Solution
T = int(input())
while T > 0:
    X, Y, A, B, K = map(int, input().split())
    petrol_price = X + (A * K)
    diesel_price = Y + (B * K)
    if (petrol_price < diesel_price):
        print("PETROL")
    elif (diesel_price < petrol_price):
        print("DIESEL")
    else:
        print("SAME PRICE")
    T = T - 1
                System.out.println("SAME PRICE");
            }
            test = test - 1;
        }
    }
}

Which Fuel is Cheaper CodeChef Solution in CPP

//Which Fuel is Cheaper | CodeChef Solution
#include <iostream>
using namespace std;
int main() {
    int test;
    cin >> test;
    while(test--){
    int X, Y, A, B, K, petrol_price, diesel_price;
    cin >> X >> Y >> A >> B >> K;
    petrol_price = X + (A * K);
    diesel_price = Y + (B * K);
    if (petrol_price < diesel_price){
        cout << "PETROL" << endl;
    }
    else if (diesel_price < petrol_price){
        cout << "DIESEL" << endl;
    }
    else{
        cout << "SAME PRICE" << endl;
    }
    }
    return 0;
}

Which Fuel is Cheaper CodeChef Solution in Python

/* package codechef; // don't place package name! */
import java.util.Scanner;
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 input = new Scanner(System.in);
        int test = input.nextInt();
        while (test > 0){
            int X = input.nextInt();
            int Y = input.nextInt();
            int A = input.nextInt();
            int B = input.nextInt();
            int K = input.nextInt();
            int petrol_price = X + (A * K);
            int diesel_price = Y + (B * K);
            if (petrol_price < diesel_price){
                System.out.println("PETROL");
            }
            else if (diesel_price < petrol_price){
                System.out.println("DIESEL");
            }
            else{
                System.out.println("SAME PRICE");
            }
            test = test - 1;
        }
    }
}

Disclaimer: The above Problem (Which Fuel is Cheaper CodeChef) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Equal Coins CodeChef Solution

Leave a Reply

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