Algorithm


 problem Link  :https://www.codechef.com/problems/SIXFRIENDS 

Problem

Six friends go on a trip and are looking for accommodation. After looking for hours, they find a hotel which offers two types of rooms — double rooms and triple rooms. A double room costs Rs. , while a triple room costs Rs. .

The friends can either get three double rooms or get two triple rooms. Find the minimum amount they will have to pay to accommodate all six of them.

Input Format

  • The first line contains a single integer  - the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two integers  and  - the cost of a double room and the cost of a triple room.

Output Format

For each testcase, output the minimum amount required to accommodate all the six friends.

Constraints

  • 1≤�≤100
  • 1≤�<�≤100

Sample 1:

Input
 
Output
 
3
10 15
6 8
4 8
30
16
12

Explanation:

Test case 1: The friends can take three double rooms and thus pay a total of Rs. 30.

Test case 2: The friends can take two triple rooms and thus pay a total of Rs. 16.

Test case 3: The friends can take three double rooms and thus pay a t

Code Examples

#1 Code Example with C Programming

Code - C Programming

 #include<stdio.h>
int main()
{
    int t,x,y;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&x,&y);
        if(3*x>=2*y) printf("%d\n",2*y);
        else printf("%d\n",3*x);
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
10 15
6 8

Output

x
+
cmd
30
16
12
Advertisements

Demonstration


CodeChef solution SIXFRIENDS  - Six Friends solution  in C,C++

Previous
CodeChef solution INVESTMENT - Good Investment or Not solution in C,C++
Next
CodeChef solution ADVANCE - Rating Improvement solution in Codechef solution in C,C++

Category - CodeChef Online Judge   Maniruzzaman Akash   10 months ago   405   0