Which Fuel is Cheaper CHEAPFUEL Solution Codechef

Which Fuel is Cheaper CHEAPFUEL Solution

The current price of petrol is XX rupees, and the current price of diesel is YY rupees. At the start of each month, the price of petrol increases by AA rupees and the price of diesel increases by BB rupees.

Chef is curious to know which fuel costs less at the end of the KthKth month. If petrol is cheaper than diesel at the end of KthKth month, then print PETROLPETROL. If diesel is cheaper than petrol at the end of the KthKth month, then print DIESELDIESEL. If both the fuels have the same price at the end of the KthKth month, then print SAME PRICESAME PRICE.

Input Format

  • The first line of input contains a single integer TT, denoting the number of test cases. The description of TT test cases follows.
  • Each test case consists of a single line of input, containing five space-separated integers X,Y,A,B,KX,Y,A,B,K.

Output Format

For each test case,

  • Print PETROLPETROL if petrol is cheaper than diesel.
  • Print DIESELDIESEL if diesel is cheaper than petrol.
  • Print SAME PRICESAME PRICE otherwise.

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

Constraints

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

Subtasks

  • Subtask 1 (100 points): Original constraints

Sample Input 1 

3
1 1 1 1 1
2 1 2 1 2
2 2 1 1 2

Sample Output 1 

SAME PRICE
DIESEL
SAME PRICE

Explanation

Test case 1:

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

Test case 2:

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

Test case 3:

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

SOLUTION

Program Python: Which Fuel is Cheaper CHEAPFUEL Solution in Python

# cook your dish here
for _ in range(int(input())):
    a,b,c,d,e = map(int, input().split())
    p= a + (c * e)
    d = b + (d * e)
    
    if (p < d):
        print("PETROL")
    elif (d < p):
        print("DIESEL")
    else:
        print("SAME PRICE")

Program C++: Which Fuel is Cheaper CHEAPFUEL Solution in C++

#include <iostream>
using namespace std;

int main() {
    int t;
    cin >> t;
    while(t--){
    
    int a,b,c,d,e,p,dp;
    cin >> a >> b >> c >> d >> e;
    p = a + (c * e);
    dp = b + (d * e);
    
    if (p < dp){
        cout << "PETROL" << endl;
    }
    else if (dp < p){
        cout << "DIESEL" << endl;
    }
    else{
        cout << "SAME PRICE" << endl;
    }
    }
    return 0;
}

Program Java: Which Fuel is Cheaper CHEAPFUEL Solution in Java

import java.util.Scanner;
import java.lang.*;
import java.io.*;
class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        while (t > 0){
            
            int a = input.nextInt();
            int b = input.nextInt();
            int c = input.nextInt();
            int d = input.nextInt();
            int e = input.nextInt();
            
            int p = a + (c * e);
            int dp = b + (d * e);
            
            if (p < dp){
                System.out.println("PETROL");
            }
            else if (dp < p){
                System.out.println("DIESEL");
            }
            else{
                System.out.println("SAME PRICE");
            }
            t = t - 1;
        }
    }
}

November Long Challenge 2021 Solution

Codechef Long Challenges Solution

October Long Challenge 2021 Solution

September Long Challenge 2021 Solution

Leave a Comment