TV Discount Codechef Solution

Hello Programmers In this post, you will know how to solve the TV Discount Codechef Solution. The Problem Code is TVDISC.

TV Discount Codechef Solution
TV Discount 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.


Chef is looking to buy a TV and has shortlisted two models. The first one costs AA rupees, while the second one costs BB rupees.

Since there is a huge sale coming up on Chefzon, Chef can get a flat discount of C rupees on the first TV, and a flat discount of D rupees on the second one.

Help Chef determine which of the two TVs would be cheaper to buy during the sale.

Input Format

  • The first line contains a single integer T — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains four space-separated integers A, B, C, and D — the marked price (in rupees) of the first TV, the marked price (in rupees) of the second TV, the flat discount (in rupees) of the first TV, and the flat discount (in rupees) of the second TV.

Output Format

For each test case, print a single line containing the string First if the first TV is cheaper to buy with discount, or Second if the second TV is cheaper to buy with discount. If both of them cost the same after discount, print Any.

You may print each character of the string in uppercase or lowercase (for example, the strings firstFirstfIRSt, and FIRST will all be treated as identical).


  • 1≤T≤5000

Sample 1:


85 75 35 20
100 99 0 0
30 40 0 10




Test case 11: The cost of the first TV after discount is 85 – 35 = 50, while the cost of the second TV after discount is 75 – 20 = 55. Thus the first TV is cheaper to buy than the second.

Test case 22: The cost of the first TV after discount is 100 – 0 = 100, while the cost of the second TV after discount is 99 – 0 = 99 Thus the second TV is cheaper to buy than the first.

Test case 33: The cost of the first TV after discount is 30 – 0 = 30, while the cost of the second TV after discount is 40 – 10 = 30. Since they are equal, Chef can buy any of them.

TV Discount 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 a=sc.nextInt();
		    int b=sc.nextInt();
		    int c=sc.nextInt();
		    int d=sc.nextInt();
		    int x=a-c;
		    int y=b-d;
		    else if(y>x)

TV Discount Codechef Solution in CPP

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d",x)
#define pl(x)	printf("%lld",x)
#define ps(s)	printf("%s",s)
#define pnl()   printf("\n")
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 18 * 103, M = N;
#define top(a,b) (ll)((a+b-1)/b)
vi g[N];
void matrix(ll n, ll m){
  char s[101][101];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
int fact(ll n);
// Returns factorial of n
int fact(ll n)
    ll res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
int gcd(int a, int b)
    if (a == 0)
        return b;
    return gcd(b % a, a);
int main() {
  ll t;
  cin >> t;
    ll a , b, c, d;
    cin >> a >> b >> c >> d;
    a = a - c;
    b = b - d;
    if(a > b)
        cout << "SECOND" << endl;
    else if(a < b)
        cout << "FIRST" << endl;
    else if(a == b)
        cout << "ANY" << endl;
  return 0;
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  return result;
void ipgraph(int n, int m){
	int i, u, v;
void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);

TV Discount Codechef Solution in Python

# cook your dish here
t = int(input())
for i in range(t):
    x,y,z,a = map(int,input().split())
    b = x - y
    c = z - a
    if (b == c):
    elif (b > c):

Disclaimer: The above Problem (TV Discount Codechef Solution) 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: A Big Sale Codechef Solution

Leave a Reply

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