Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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:
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?
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.
Input:
3
4 0
5 3
3 3
Output:
4
8
5
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
# 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))
#include <iostream>
using namespace std;
int main() {
// your code goes here
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;
}
/* 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
// your code goes here
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));
}
}
}
}
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
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 >>