Problem:
Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.

Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:

Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.

At least how many explosions do you need to cause in order to vanish all the monsters?

Constraints

All input values are integers.

1 ≤ N ≤ 10^5

1 ≤ B < A ≤ 10^9

1 ≤ h_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N A B
h_1
h_2
:
h_N

Output

Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.

Sample Input 1

4 5 3
8
7
4
2

Sample Output 1

2

You can vanish all the monsters in two explosion, as follows:

First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.

Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.

Sample Input 2

2 10 4
20
20

Sample Output 2

4

You need to cause two explosions centered at each monster, for a total of four.

Sample Input 3

5 2 1
900000000
900000000
1000000000
1000000000
1000000000

Sample Output 3

800000000

Solution in Ruby (2.3.3) (judge verdict: Time Limit Exceeded)

N, A, B = gets.chop.split.map(&:to_i)
H = [0]
N.times do
  H << gets.chop.to_i
end

@dp = []
@dp << [{total_hit: 0, life_list: H, count: 0}]

def attack(target, life_list, power_rate)
  hit = 0
  (1..N).to_a.each do |i|
    attack_point = target == i ? A * power_rate : B * power_rate
    damage = life_list[i] < attack_point ? life_list[i] : attack_point
    life_list[i] -= damage
    hit += damage
  end
  [hit, life_list]
end

def continuous_attack(o)
  power_rate = 1
  dead_list = o[:life_list].map do |i|
                i == 0
              end
  loop do
    max_life_target = nil
    max_life = 0
    enable_attack = true
    (1..N).to_a.each do |i|
      target_life = o[:life_list][i]
      if target_life > max_life
        max_life = target_life
        max_life_target = i
      end
      enable_attack = target_life > A * power_rate * 5 if enable_attack && dead_list[i] == false
    end
    break if max_life_target.nil? || !enable_attack
    hit, life_list = attack(max_life_target, o[:life_list].dup, power_rate)
    o[:total_hit] += hit
    o[:life_list] = life_list
    o[:count] += power_rate
    power_rate *= 2
  end
end

def dispersion(array)
  mean = array.inject(&:+).to_f / array.size
  dispersion = array.inject(0) do |sum, i|
                 sum + (i - mean) ** 2
               end
end

def start
  i = 1
  total_life = H.inject(&:+)
  loop do
    @dp << []
    (1..N).to_a.each do |j|
      max_hit = 0
      max_hit_pattern = nil
      now_count = nil
      min_life_dispersion = nil
      @dp[i-1].each do |o|
        next if o[:life_list][j] == 0
        continuous_attack(o)
        hit, result_life_list = attack(j, o[:life_list].dup, 1)
        sum = hit + o[:total_hit]
        target_life = o[:life_list][j]
        life_dispersion = dispersion(o[:life_list])
        min_life_dispersion = life_dispersion if min_life_dispersion.nil?
        if sum > max_hit
          max_hit = sum
          max_hit_pattern = result_life_list
          now_count = o[:count] + 1
          max_life_dispersion = life_dispersion
        elsif sum == max_hit && life_dispersion < min_life_dispersion
          max_hit_pattern = result_life_list
          min_life_dispersion = life_dispersion
          now_count = o[:count] + 1
        end
      end
      return now_count if max_hit == total_life
      next if max_hit_pattern.nil?
      @dp[i] << {total_hit: max_hit, life_list: max_hit_pattern, count: now_count, dispersion: min_life_dispersion}
    end
    @dp[i].uniq!
    i += 1
  end
end

p start