-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinding shoes
33 lines (29 loc) · 1.13 KB
/
finding shoes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Problem
Chef has N friends. Chef promised that he would gift a pair of shoes (consisting of one left shoe and one right shoe) to each of his
N friends. Chef was about to go to the marketplace to buy shoes, but he suddenly remembers that he already had M left shoes.
What is the minimum number of extra shoes that Chef will have to buy to ensure that he is able to gift a pair of shoes to each of his N friends?
For example, if N=2,M=4, then Chef already has 4 left shoes, so he must buy 2 extra right shoes to form 2 pairs of shoes.
Therefore Chef must buy at least 2 extra shoes to ensure that he is able to get N=2 pairs of shoes.
/* 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 t=sc.nextInt();
for(int i=0;i<t;i++){
int a=sc.nextInt();
int b=sc.nextInt();
if(a<b){
System.out.println(a);
}else
{
System.out.println((a-b)+a);
} // your code goes here
}
}
}