Problem Statement
Currently, Quimey and Pablo have no money at all. During the following N days they are going to earn some money and they will use it to buy the T-shirts. The days are numbered from 0 (today) to N-1 (the day N-1 days in the future).
For each valid i, Q[i] and P[i] are the amounts in pesos Quimey and Pablo will earn on day i. (Note that each of those amounts is at most T. Therefore, Quimey and Pablo will be able to buy at most one T-shirt each day.)
For example, suppose that a T-shirt costs T=10 pesos. If Q={2,3,5,10}, the following will happen to Quimey:
- On day 0, he earns 2 pesos. He now has 2 pesos.
- On day 1, he earns 3 pesos. He now has 5 pesos.
- On day 2, he earns 5 pesos. He now has 10 pesos, which is enough to buy a T-shirt. He goes to the store and buys one. Afterwards, he has 0 pesos left.
- On day 3, he earns 10 pesos. He then goes to buy a second T-shirt. Afterwards, he again has 0 pesos left.
You are given the
Definition
- Class:
- BuyingTshirts
- Method:
- meet
- Parameters:
- int, int[], int[]
- Returns:
- int
- Method signature:
- int meet(int T, int[] Q, int[] P)
- (be sure your method is public)
Notes
- If you need the number N in your solution, you can determine it as the number of elements in Q.
Constraints
- T will be between 1 and 100.
- Q will contain between 1 and 100 elements.
- Q and P will contain the same number of elements.
- Each element of Q will be between 1 and T.
- Each element of P will be between 1 and T.
Examples
5
{1,2,3,4,5}
{5,4,3,2,1}
Returns: 2
Quimey will buy his T-shirts on days 2, 3, and 4. Pablo will buy his on days 0, 2, and 4. They will go to the store together twice: first on day 2 and then on day 4.
10
{10,10,10}
{10,10,10}
Returns: 3
2
{1,2,1,2,1,2,1,2}
{1,1,1,1,2,2,2,2}
Returns: 5
They will both go to the store on the following days: 1, 3, 5, 6, and 7.
100
{1,2,3}
{4,5,6}
Returns: 0
In this test case they do not buy any T-shirts at all.
10
{10,1,10,1}
{1,10,1,10}
Returns: 0
68
{11,62,55,35,62,26,34,4,68,24,27,21,14,67,8,16,34,32,36,8,43,62,46,34,48,23,46,20,58,9,23,17,65,21,43,47,27,47,50,46,13,57}
{49,17,51,53,62,32,16,43,65,53,18,7,17,40,35,47,57,52,35,12,6,41,28,1,37,50,8,18,31,44,7,51,35,5,6,66,51,26,13,44,31,9}
Returns: 11
77
{72,5,64,71,26,61,60,20,67,41,27,17,52,34,59,16,40,76,26,17,28,16,2,30,77,67,58,34,8,24,44,32,18,13,54,52,9,59,66,30,61,51,58,54,14,34,43,54,8,48,33,33,9,21,66,22,65,71,42,42,7,65,70,52,39,14,32}
{52,23,5,56,4,64,8,14,75,74,57,25,54,55,20,35,47,3,51,21,41,73,11,43,8,19,45,66,55,57,32,76,18,63,21,39,46,56,16,38,19,37,10,75,23,76,38,75,65,16,6,33,77,35,73,44,71,50,14,64,43,75,39,55,4,22,48}
Returns: 16
4
{1,3,1,3,2,2,1,3,3,3,3,4,1,3,1}
{1,3,1,2,3,2,3,1,4,2,4,1,4,3,4}
Returns: 5
47
{43,29,25,16,27,30,11,33,22,47,16,42,2,7,28,21,25,17,42,10,34,13,2,19,41,4,16,19,5}
{46,46,27,7,39,40,13,42,44,44,20,33,25,14,21,11,40,31,23,7,40,35,28,23,28,6,19,13,41}
Returns: 11
24
{8,8,14,19,2,10,15,9,24,19,21,3,18,10,1,9,18,2,7,2,13,2,16,14,21,13,22,19,18,11,11,9,20,7,3,6,3,7,13,2}
{5,2,14,14,12,17,2,11,7,14,8,24,20,14,9,18,13,23,23,17,15,2,3,3,12,16,9,15,10,10,15,3,18,24,2,23,1,3,24,15}
Returns: 10
98
{71,36,98,43,65,10,1,50,74,48,28,36,62,88,65,73,31,78,70,61,40,14,81,34,43,50,90,19,21,26,73,38,39,50,57,93,93,27,71,88,11,43,68,80,78,44,42,43,26,14,4,89,29,33,4,42,84,97,5,41,43,31,45,36,12,89,50,52,10,44,6,55,58,2,46,96,95,8,75,59,1,36,56,59,22,76,22,22}
{44,29,23,70,53,82,82,78,63,83,70,91,56,96,45,25,61,31,7,65,62,85,62,7,73,65,68,37,39,25,54,5,45,25,56,65,54,30,44,23,14,35,58,69,50,79,3,67,97,32,88,29,81,41,98,68,59,29,8,76,12,74,37,72,25,70,21,71,13,90,17,85,43,73,89,17,49,80,89,48,30,46,60,87,19,77,32,22}
Returns: 24
66
{26,55,42,21,55,8,27,34,54,36,56,46,61,38,10,54,43,26,25,38,50,54,13,13,33,42,26,56,9,24}
{23,24,1,35,11,48,60,42,20,13,3,33,44,46,6,51,57,38,41,64,63,3,14,32,55,37,10,40,45,56}
Returns: 8
79
{15,15,8,7,21,70,68,56,54,9,64,79,78,8,4,20,54,64,64,76,63,12,45,69,60}
{37,34,71,7,58,2,44,53,24,52,62,57,39,39,41,70,22,16,38,69,73,11,28,75,36}
Returns: 5
75
{52,41,39,25,68,46,53,26,49,63,55,72,7,11}
{3,59,68,52,10,29,35,37,71,73,54,14,39,47}
Returns: 4
41
{29,35,7,3,13,15,17,25,14,20,36,21,40,7,33,41,37,40,29,8,18,11,35,13,33,39,35,29,10,33,24,7,31,35,25,25,2,37,29,11,27,37,16,14,32,39,32,25,31,33,20,41,12,7,40,30,14,9,16,15,4,24,2,18,24,16,34,24,24,27,30,2,11,5,29,15,28,12,27,23,26,18,9,9,40,25,38,14,1,20}
{41,4,22,8,32,23,25,14,37,30,6,13,24,11,5,37,9,7,32,34,37,37,39,7,2,33,31,19,39,10,19,8,27,40,37,20,35,11,37,8,38,1,28,5,5,39,3,32,9,34,6,26,4,14,38,37,22,11,35,23,6,41,6,32,9,11,7,3,25,7,3,5,11,28,22,5,6,2,30,30,14,32,3,7,8,7,13,28,14,36}
Returns: 21
49
{9,1,13,10,8,46,11,43,45,3,35,32,26,4,14,40,46,46,10,7,26,7,5,29,6,14,34,2,31,35,10,44,17,18,46,6,9,29,34,25,23,15,37,25,24,35,27,32,23,12,24,22,7,20,2,46,18,44,22,8,18,24,14,4,5,9,9,11,18,7,18,41,9,26,9,44,36,25,27,38,35,11,38,20,18,15,7,20,4,15}
{32,16,15,15,23,31,16,31,45,30,4,10,41,12,15,26,35,9,1,1,46,25,2,36,44,33,30,24,25,14,27,5,3,25,13,13,49,48,47,24,43,34,37,1,48,2,39,44,49,10,25,27,6,42,31,22,3,1,38,32,33,30,11,43,19,17,4,33,24,7,37,28,47,13,4,42,29,21,11,24,32,13,38,12,29,27,18,18,6,10}
Returns: 18
8
{3,5,7}
{7,1,8}
Returns: 1
49
{16,43,41,42,10,6,14,40,22,21,14,26,47,18,33,42,21,15,33,7,34,5,24,7,1,6,37,29,43,40,12,46,41,36,26,10,21,49,31,25,39,37,28,26,27,20,13,31,41,33,47,48,40}
{2,19,13,23,4,34,25,21,34,14,7,39,9,3,19,46,19,28,16,35,47,27,8,4,47,26,25,26,33,20,5,42,39,7,7,9,27,24,42,30,48,12,13,27,39,4,27,4,29,40,42,13,4}
Returns: 11
75
{10,46,65,48,59,19,11,25,11,58,46,50,53,36,73,23,53,31,70,69,7,48,4,13,34,34,60,30,45,21,67,43,38,32,73,59,7,9,49,44,71,8,66,50,28,19,3,19,22,29,27,48,29,9,59,14,44,2,4,26,18,45,16,14,35,48,2,3,46,40,16,63,5,70,43,58,52,21,27,14,59,43,48,60,19,18,64,33,40,34,39,33,65,66}
{1,49,37,44,7,2,73,5,3,42,65,15,56,25,47,48,40,46,1,5,38,40,63,43,66,49,35,12,59,32,26,68,33,75,72,48,52,24,58,2,62,7,1,37,70,35,19,17,59,3,47,63,3,71,61,13,14,1,12,25,30,7,18,69,48,31,18,3,28,32,49,74,21,3,36,34,38,54,9,36,62,61,4,67,54,41,7,26,74,37,57,29,11,51}
Returns: 25
87
{4,20,55,80,68,62,6,54,34,12,84,77,53,46,15,5,16,64,41,28,51,19,33,33,56,35,30,45,11,65,82,14,2,47,82,74,3,87,74,55,81,42,7,61,73,49,28,41,40,59,16,64,54,8,18,58,49,83,79,62,30,40,64,33,20,42,68,20,4,42,76,19,8,86,1,70,69,1,40,49,83,2,77,56,49,84,57}
{9,36,87,3,83,29,56,21,60,45,31,33,75,18,71,46,6,25,16,11,57,73,48,46,7,3,80,58,17,43,1,4,86,14,82,65,10,56,10,9,44,58,24,42,57,25,39,30,60,70,69,84,52,15,67,10,45,28,44,84,77,70,63,47,38,58,4,44,13,44,86,87,3,49,66,38,56,20,80,37,21,33,10,58,50,25,4}
Returns: 20
18
{14,7,8,11,2,4,13,3,2,11,18,13,6,12,15,13,4,16,6,1,4,3,8,5,11,5,14,10,4,14,17,11,4,1,18,5,4,11,8,13,14,5,17,12,18,13,1,16,15,11,6,18,14,1,7,14,12,11,8,12,3,12,18,14,9,10,13,4,4,9,12,18,11,17,11,10,13,7}
{1,6,17,4,6,2,7,2,15,18,7,6,12,10,1,11,16,9,8,12,6,3,1,6,5,2,10,18,5,8,17,2,3,9,13,1,6,12,4,18,3,18,2,12,17,10,11,15,2,16,17,3,7,11,6,16,12,8,8,15,18,4,3,6,10,7,8,17,4,9,15,6,8,11,11,5,12,7}
Returns: 19
89
{28,44,80,73,2,30,84,70,69,50,27,4,52,86,22,47,89,40,33,34,39,73,40,26,12,9,46,58,53,11}
{7,54,11,36,18,83,5,38,65,63,61,34,21,59,6,1,28,88,12,66,71,72,51,9,17,5,29,29,67,31}
Returns: 7
62
{34,16,60,28,19,10,59,37,61,26,23,22,13,61,1,36,34,46,37,62,33,13,42,42,44,23,32,60,8,1,10,31,9,7,53,15,2,24,27,16,50,20,44,44,3,48,58,22,23,41,34,43,50,8,34,32,28,62,57,40,54,28,13,45,2,7,58,2,45,23,58,54,39,8,20,34,24,42,57,52,18,40,60,39,28,28,4,60}
{34,61,42,33,62,28,20,47,58,49,51,12,28,52,53,38,18,56,50,33,52,49,22,9,43,39,25,49,15,39,17,37,49,60,53,36,15,37,26,21,29,57,53,18,33,39,61,5,11,27,43,23,50,10,11,20,54,2,12,38,37,58,5,31,38,17,29,30,36,53,31,59,35,28,13,30,19,47,48,41,43,2,35,56,10,16,35,32}
Returns: 25
46
{28,7,13,7,6,13,46,20,38,46,40,34,27,44,27,16,36,8,45,5,4,7,14,41,8,13,31,26,13,20,38,1,15,30,10,41,12,43,36,19,7,43,1,26,29,44,14,22,42,12,20,41,7,8,21,18,25,26,7,40,7,27,46,27,36,44,6,27,40,39,16,30,2,37,35,20,24,34,30,35,33,16,22,14,1,7,9,6,41,26,42,42,31,5,2,42,34,46,5}
{5,33,8,9,4,15,32,3,32,8,24,32,36,27,34,6,45,11,5,2,5,27,17,24,23,12,18,33,33,6,15,20,22,24,11,23,3,3,38,40,7,38,44,27,38,22,17,15,43,16,16,26,6,29,27,20,15,19,4,4,21,4,10,20,18,10,4,34,22,15,42,22,3,11,24,9,12,41,36,14,26,21,28,39,43,12,45,21,4,29,23,27,13,38,38,4,9,20,40}
Returns: 22
24
{19,1,11,3,9,12,12,21,8,16,5,11,9,8,24,2,3,10,14,3,23,19,4,3,3,1,24,20,19,7,16,2,19,5,11,14,6,13,13,22,10,7,23,19,17,22,13,18,18,17,15,4,14,11,17,22,3,4,11,17,13,21,17,3,24,15,4,4,15,5,15,18,17,14,19,14,22,12,12,21,22,7,17,8,18,19,16,4,17,14,23,10,20,11,12,24,11,17,23,22}
{4,4,21,24,22,11,8,20,5,20,4,8,16,6,19,13,7,2,6,24,2,8,7,18,16,11,7,7,17,24,9,15,12,19,14,24,2,18,7,18,1,16,6,2,11,11,21,7,12,22,20,24,23,24,24,12,9,11,7,24,12,22,21,13,5,20,10,7,15,19,10,15,6,21,12,18,21,2,19,8,17,21,24,13,11,18,13,4,10,14,19,7,14,7,22,16,14,24,12,4}
Returns: 30
87
{27,27,71,53,50,2,79,25,64,51,9,26,59,13,44,42,42,80,61,4,15,75,36,57,13,66,31,77,41,43,12,36,37,36,3,33,52,14,61,21,33,27,79,68,77,29}
{54,50,19,19,70,45,53,73,11,87,26,32,37,52,20,60,78,50,22,12,7,67,16,11,35,8,53,58,12,1,58,52,24,48,17,24,77,47,78,46,66,52,59,85,43,84}
Returns: 10
67
{67,17,40,66,62}
{25,59,22,42,59}
Returns: 2
91
{59,58,4,52,27,55,73,88,49,65,37,16,26,68,89}
{84,44,7,63,31,54,41,83,27,47,23,13,7,48,89}
Returns: 4
84
{2,3,52,73,2,49,9,58,11,11,62,13,31,80,76,19,80,39,50,11,29,77,58,62,50,18,78,38,52,27,76,84,82,35,74,4,69,45,18,41,10,59,7,10,11,55,11,82,5,65,51,53,13,18,50,5,66,32,10,38,72,28,9,2,60,6,29,54,70,20,13,11,38,75,38,66,36,1,82,5,56,10,33,7,34,15,47,79}
{39,39,42,51,35,38,77,65,58,48,14,6,26,1,78,36,65,2,71,31,64,16,63,71,9,43,23,41,76,36,8,71,42,64,77,23,82,67,15,52,78,58,71,73,48,74,80,72,26,66,43,64,77,16,33,20,3,29,36,26,65,28,38,12,21,40,13,50,17,39,77,74,3,59,45,11,38,9,6,58,36,9,7,56,26,75,23,15}
Returns: 25
25
{23,5,9,19,17,14,20,16,15,9,4,13,25,3,14,24,3,5,7,9,12,12}
{2,20,3,19,3,1,19,10,7,8,15,15,21,5,17,18,22,22,10,9,9,5}
Returns: 5
100
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
Returns: 100
2
{1, 2, 1, 2, 1, 2, 1, 2 }
{1, 1, 1, 1, 2, 2, 2, 2 }
Returns: 5
4
{1, 2, 1, 2, 1, 2, 1, 2 }
{1, 1, 1, 1, 2, 2, 2, 2 }
Returns: 2
10
{10, 1, 10, 1 }
{1, 10, 1, 10 }
Returns: 0
5
{1, 2, 3, 4, 5 }
{5, 4, 3, 2, 1 }
Returns: 2
5
{2, 4 }
{2, 4 }
Returns: 1
5
{5, 5, 5, 5, 5, 5, 5, 5, 5 }
{5, 5, 5, 5, 5, 5, 5, 5, 5 }
Returns: 9
20
{19, 19 }
{1, 5 }
Returns: 0
6
{1, 1, 1, 1, 1 }
{1, 1, 1, 1, 1 }
Returns: 0
3
{2, 2, 2 }
{2, 2, 2 }
Returns: 2
10
{1, 1, 1, 1, 1, 1, 1, 1, 1 }
{10, 10, 10, 10, 10, 10, 10, 10, 10 }
Returns: 0
12
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
{12, 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
Returns: 0