結果

問題 No.1430 Coup de Coupon
ユーザー materialmaterial
提出日時 2021-03-14 17:19:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-24 00:27:05
合計ジャッジ時間 3,969 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,288 KB
testcase_01 AC 82 ms
12,288 KB
testcase_02 AC 85 ms
12,288 KB
testcase_03 AC 95 ms
12,160 KB
testcase_04 AC 96 ms
12,288 KB
testcase_05 AC 97 ms
12,416 KB
testcase_06 AC 104 ms
12,288 KB
testcase_07 AC 108 ms
12,544 KB
testcase_08 AC 109 ms
12,288 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 106 ms
12,416 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 89 ms
12,288 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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!{|a, b| b <=> a}

  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!{|a, b| b <=> a}
  cs2.sort!{|a, b| b <=> a}

  total = 0
  ps.each do |price|
    type1_discount = 0
    type1_discount = [cs1[0], price].min    if cs1.size > 0

    type2_discount = 0
    type2_discount = cs2[0] * (price / 100) if cs2.size > 0

    discount = 0
    if cs1.size > 0 && cs2.size > 0 then
      if type1_discount >= type2_discount then
        discount = type1_discount
        cs1.shift
      else
        discount = type2_discount
        cs2.shift
      end
    elsif cs1.size > 0 then
      discount = type1_discount
      cs1.shift
    elsif cs2.size > 0 then
      discount = type2_discount
      cs2.shift
    end

    total += [price - discount, 0].max
  end
  puts total.to_s
end

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