304 North Cardinal St.
Dorchester Center, MA 02124

# Avoid Contact CodeChef Solution

## Problem – Avoid Contact CodeChef Solution

A hostel has N rooms in a straight line. It has to accommodate X people. Unfortunately, out of these X people, Y of them are infected with chickenpox. Due to safety norms, the following precaution must be taken:

• No person should occupy a room directly adjacent to a room occupied by a chickenpox-infected person. In particular, two chickenpox-infected people cannot occupy adjacent rooms.

For example, if room 4 has a chickenpox-infected person, then nobody should occupy rooms 3 and 5. Similarly, if room 1 has a chickenpox-infected person then nobody should occupy room 2.

What’s the minimum value of N for which all the people can be accommodated in the hostel, following the above condition?

### Input Format

• The first line of 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 two integers X and Y — the total number of people and the number of chickenpox-infected people.

### Output Format

For each test case, output on a new line a single integer — the minimum value of N for which all the people can be accommodated in the hostel.

• 1≤T≤200
• 1≤X≤1000
• 0≤YX

### Sample 1:

``````Input:
3
4 0
5 3
3 3
Output:
4
8
5
``````

### Explanation:

Note: Below, C represents a room occupied by a chickenpox-infected person, N represents a room occupied by an uninfected person, and __ represents an empty room.

Test case 1: One of the possible ways to accommodate the people in 4 rooms is:

N N N N

Test case 2: One of the possible ways to accommodate the people in 8 rooms is:

C __ C __ N N __ C

Test case 3: One of the possible ways to accommodate the people in 5 rooms is:

C __ C __ C

## Avoid Contact CodeChef Solution in Pyth 3

``````# cook your dish here
t=int(input())
for i in range(t):
x,y=map(int,input().split())
if x==y:
print((x-y)+(y*2)-1)
elif x>y:
print((x-y)+(y*2))``````

## Avoid Contact CodeChef Solution in C++17

``````#include <iostream>
using namespace std;

int main() {
int t,x,y;
cin>>t;
while(t--)
{
cin>>x>>y;
if(x==y)
cout<<x+x-1<<endl;
else if(x!=y)
cout<<x+y<<endl;
}
return 0;
}``````

## Avoid Contact 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
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
int a=sc.nextInt();
int b=sc.nextInt();
if(b==0){
System.out.println(a);

}
else if(a==b){
System.out.println((b*2-1)+(a-b));
}
else{
System.out.println((b*2)+(a-b));
}
}
}
}
``````
##### Avoid Contact CodeChef Solution Review:

In our experience, we suggest you solve this Avoid Contact 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 Avoid Contact CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Avoid Contact 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