結果
問題 |
No.1015 おつりは要らないです
|
ユーザー |
|
提出日時 | 2022-01-26 18:29:13 |
言語 | Scala(Beta) (3.6.2) |
結果 |
AC
|
実行時間 | 1,903 ms / 2,000 ms |
コード長 | 673 bytes |
コンパイル時間 | 11,858 ms |
コンパイル使用メモリ | 260,052 KB |
実行使用メモリ | 81,492 KB |
最終ジャッジ日時 | 2024-12-23 12:05:01 |
合計ジャッジ時間 | 66,850 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
import scala.annotation.tailrec import scala.io.StdIn.* import scala.math.* @main def main = val Array(n, x, y, z) = readLine().split(' ').map(_.toInt) val pay = readLine().split(' ').map(_.toInt) val bill = Array(1000 -> x, 5000 -> y, 10000 -> z) for (money, count) <- bill.reverseIterator do var rest = count for i <- 0 until n do if pay(i) > 0 then val use = min(rest, pay(i) / money) pay(i) -= use * money rest -= use for i <- (0 until n).sortBy(i => pay(i) % money).reverseIterator do if rest > 0 && pay(i) >= 0 then rest -= 1 pay(i) -= money println(if pay.forall(_ < 0) then "Yes" else "No")