Bleed Magic
Rishi and his gang of wizards are hunting the Radiant Sky Pheonix, a legendary bird they're sure will make for a good kebab. Since the phoenix is a magical creature, the wizards must use magical attacks to defeat it.
There are wizards, each with a power
. To launch an attack on the phoenix, the wizards combine all their powers using a bitwise OR to obtain a total power
. For the attack to succeed,
must be at least
.
However, these attacks are tiring! After each attack, exactly one bit from exactly one of the wizards' powers must change from set to unset (). For example, if a wizard has a power of
(
1011 in binary), then their power could change to (
1010), (
1001) or (
0011) after an attack. The wizards get to choose who loses a bit, and which bit is cleared.
Assuming the wizards play optimally, determine the maximum number of attacks they can perform on the phoenix before their combined power falls below .
Input
The first line contains a two integers, and
, the number of wizards in Rishi's gang, and the power needed to make a successful attack.
The second line contains integers,
(
), where
is the power of the
th wizard.
Output
Output the maximum number of attacks the wizards can make, while their power stays above .
Example
Input 1
3 10
11 9 4
Output 1
5
The wizards can make 5 attacks in total. Below is one way they could achieve this, although it is not the only way.
Initial State:
Wizard 1: 11 (1011)
Wizard 2: 9 (1001)
Wizard 3: 4 (0100)
Total Power: 15 (1111)
After Attack 1:
Wizard 1: 10 (1010) [lost fourth bit]
Wizard 2: 9 (1001)
Wizard 3: 4 (0100)
Total Power: 15 (1111)
After Attack 2:
Wizard 1: 2 (0010) [lost first bit]
Wizard 2: 9 (1001)
Wizard 3: 4 (0100)
Total Power: 15 (1111)
After Attack 3:
Wizard 1: 2 (0010)
Wizard 2: 8 (1000) [lost fourth bit]
Wizard 3: 4 (0100)
Total Power: 14 (1110)
After Attack 4:
Wizard 1: 2 (0010)
Wizard 2: 8 (1000)
Wizard 3: 0 (0000) [lost second bit]
Total Power: 10 (1010)
After Attack 5:
Wizard 1: 0 (0000) [lost third bit]
Wizard 2: 8 (1000)
Wizard 3: 0 (0000)
Total Power: 8 (1000)
Input 2
8 7
1 2 3 4 5 6 7 8
Output 2
13
Input 3
14 10
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Output 3
0
Comments