Submission #1951074


Source Code Expand

n,h = gets.chomp.split(" ").map(&:to_i)
attack = []
n.times do
  attack << gets.chomp.split(" ").map(&:to_i)
end

# 強いのから振る
# 強いのから投げる
# ある刀は振る<=投げる
# 他の刀の投げるより強い振るの場合,投げる必要ない
#
# 強い順にソート
# 振るより投げるが強い場合,そこまで投げた場合の合計ダメージになるまで殴る



attack.delete_if {|atk| attack.any?{|at| at[0] > atk[1]} }

#p attack

throw_total = 0
attack.each do |atk|
  throw_total += atk[1]
end

swing_max = attack.max_by{|atk| atk[0]}[0]
remain_hp = (h - throw_total)

ans = 0

#puts "h-throw_total :#{h} - #{throw_total} = #{h-throw_total}"
#puts "ans : #{remain_hp}"

if remain_hp > 0
  ans += remain_hp / swing_max
  h -= ans * swing_max
  if remain_hp % swing_max > 0
    ans += 1
    h -= swing_max
  end
else
  ans = 0
end

attack.sort_by{|atk| atk[1]}.each do |atk|
  h -= atk[1]
  ans += 1
  if h <= 0
    break
  end
end

puts ans

Submission Info

Submission Time
Task D - Katana Thrower
User sopurani885
Language Ruby (2.3.3)
Score 0
Code Size 1045 Byte
Status TLE
Exec Time 2108 ms
Memory 11540 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 14
TLE × 10
Set Name Test Cases
Sample a01, a02, a03, a04
All a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24
Case Name Status Exec Time Memory
a01 AC 7 ms 1788 KB
a02 AC 7 ms 1788 KB
a03 AC 7 ms 1788 KB
a04 AC 7 ms 1788 KB
b05 AC 7 ms 1788 KB
b06 TLE 2108 ms 9468 KB
b07 AC 7 ms 1788 KB
b08 TLE 2107 ms 11540 KB
b09 AC 7 ms 1788 KB
b10 AC 7 ms 1788 KB
b11 AC 7 ms 1788 KB
b12 AC 7 ms 1788 KB
b13 TLE 2107 ms 11516 KB
b14 TLE 2108 ms 9468 KB
b15 TLE 2108 ms 9468 KB
b16 TLE 2108 ms 9468 KB
b17 AC 378 ms 9468 KB
b18 AC 1554 ms 9468 KB
b19 TLE 2108 ms 9468 KB
b20 TLE 2108 ms 9468 KB
b21 TLE 2108 ms 9468 KB
b22 TLE 2108 ms 9468 KB
b23 AC 7 ms 1788 KB
b24 AC 129 ms 2172 KB