結果

問題 No.1430 Coup de Coupon
ユーザー material
提出日時 2021-03-15 18:11:43
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 1,256 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 213,120 KB
最終ジャッジ日時 2024-11-07 05:51:07
合計ジャッジ時間 4,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 TLE * 1 -- * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - total
Syntax OK

ソースコード

diff #

Greater = Proc.new {|a, b| b <=> a}

Infinity = 1e+9.to_i

def main(argv)
  (n, c) = gets.chomp.split(' ').map(&:to_i)

  ps = [0] * n
  n.times{|i| ps[i] = gets.chomp.to_i}
  ps.sort!(&Greater)
  total = ps.reduce(:+)

  cs1 = []
  cs2 = []
  c.times do |j|
    cc = gets.chomp.split(' ').map(&:to_i)
    if cc[0] == 1 then
      cs1.push(cc[1])
    else # cc[0] == 2
      cs2.push(cc[1])
    end
  end
  cs1.sort!(&Greater)
  cs2.sort!(&Greater)

  (c1, c2) = [cs1.size, cs2.size]

  dp = [nil] * (n + 1)
  (n + 1).times{|i| dp[i] = [Infinity] * (c1 + 1)}
  dp[0][0] = 0

  n.times do |i|
    if i < c then
      (c1 + 1).times do |j|
        next if j > i
        k = i - j

        dp[i + 1][j] = [dp[i + 1][j], dp[i][j] + ps[i]].min

        if j < c1 then
          new_cost_1 = [ps[i] - cs1[j], 0].max
          dp[i + 1][j + 1] = [dp[i + 1][j + 1], dp[i][j] + new_cost_1].min
        end

        if k < c2 then
          new_cost_2 = ps[i] - ((ps[i] / 100) * cs2[k])
          dp[i + 1][j + 0] = [dp[i + 1][j + 0], dp[i][j] + new_cost_2].min
        end
      end
    else
      (c1 + 1).times do |j|
        dp[i + 1][j] = [dp[i + 1][j], dp[i][j] + ps[i]].min
      end
    end
  end

  puts dp[n].min.to_s
end

main(ARGV) if self.to_s == 'main'
0