Chef and Pairing Slippers Codechef Solution

Chef and Pairing Slippers Codechef Solution: Chef has N slippers, L of which are left slippers and the rest are right slippers. Slippers must always be sold in pairs, where each pair contains one left and one right slipper. If each pair of slippers cost X rupees, what is the maximum amount of rupees that Chef can get for these slippers?

Input Format

  • The first line contains TT – the number of test cases. Then the test cases follow.
  • The first line of each test case contains three space-separated integers N, L, and X – the total number of slippers, the number of left slippers, and the price of a pair of slippers in rupees.

Output Format

For each test case, output on one line the maximum amount of rupees that Chef can get by selling the slippers that are available.


  • 1≤T≤1031≤T≤103
  • 0≤L≤N≤1030≤L≤N≤103
  • 0≤X≤1030≤X≤103

Sample Input 1 

0 0 100
10 1 0
1000 10 1000
10 7 1

Sample Output 1 



  • Test case 1: Chef has no pairs to sell, so the amount obtained is 00.
  • Test case 2: The amount earned by selling a pair is 00, so the total amount obtained is 00.
  • Test case 3: Chef can sell 1010 pairs of slippers, each giving 10001000 rupees, so the total amount earned is 1000⋅10=100001000⋅10=10000.
  • Test case 4: Chef has 1010 slippers of which 77 are left and 33 are right. Therefore Chef can sell a maximum of 33 pairs and in total can get at most 3⋅1=33⋅1=3.

Chef and Pairing Slippers CodeChef Solution in JAVA

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 in = new Scanner(;
		int testCases = in.nextInt();
		while(testCases -- > 0) {
		  int n = in.nextInt();
		  int l = in.nextInt();
		  int x = in.nextInt();
		  System.out.println(Math.min(l,Math.abs(n-l)) * x);

Chef and Pairing Slippers CodeChef Solution in CPP

#include <bits/stdc++.h>
using namespace std;
int main()
    int t;
    cin >> t;
    while (t--)
        int N, L, X;
        cin >> N >> L >> X;
        int pairs = min(N - L, L);
        cout << pairs * X << endl;
    return 0;

Chef and Pairing Slippers CodeChef Solution in Python

    n, l, x = map(int, input().split())

Disclaimer: The above Problem (Chef and Pairing Slippers) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment