Janmansh at Fruit Market CodeChef Solution

Problem – Janmansh at Fruit Market CodeChef Solution

Janmansh is at the fruit market to buy fruits for Chingari. There is an infinite supply of three different kinds of fruits with prices AB and C.

He needs to buy a total of X fruits having at least 2 different kinds of fruits. What is the least amount of money he can spend to buy fruits?

Input Format

  • The first line of the input contains a single integer T – the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains four space separated integers XABC – the number of fruits to buy and the prices of the three different types of fruits respectively.

Output Format

For each test case, output the least amount of money he can spend to buy fruits.

Constraints

  • 1 \le T \le 10^51≤T≤10^5
  • 2≤X≤1000
  • 1≤A,B,C≤100

Sample 1:

Input:
2
2 1 1 1
3 4 3 2
Output:
2
7

Explanation:

Test case-1: He can buy any two fruits of different kinds for a total price of 2.

Test case-2: He can buy 1 fruit of price 3 and 2 fruits of price 2 for a total price of 7.

Janmansh at Fruit Market CodeChef Solution in C++14

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() 
{
	int t;cin>>t;
	while(t--)
	{
	    int x,a,b,c;
	    cin>>x>>a>>b>>c;
	    int d[3]={a,b,c};
	    sort(d,d+3);
	    cout<<d[0]*(x-1)+d[1]<<endl;
	}
	return 0;
}

Janmansh at Fruit Market CodeChef Solution in Java

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

import java.util.*;
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
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int te=in.nextInt();
		while(te-->0){
		    int n=in.nextInt();
		    int ar[]=new int[3];
		    for(int i=0;i<3;i++)
		    ar[i]=in.nextInt();
		    Arrays.sort(ar);
		    
		    int res=(n-1)*ar[0];
		    res+=ar[1];
		    System.out.println(res);
}
}}

Janmansh at Fruit Market CodeChef Solution in Pyth 3

# cook your dish here
t=int(input())
for i in range(t):
    x,a,b,c=map(int,input().split())
    m=min((a+b),(b+c),(c+a))
    m1=min(a,b,c)
    print(m+(x-2)*m1)
Janmansh at Fruit Market CodeChef Solution Review:

In our experience, we suggest you solve this Janmansh at Fruit Market 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 Janmansh at Fruit Market CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Janmansh at Fruit Market 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 *