結果

問題 No.143 豆
ユーザー korogykorogy
提出日時 2017-09-04 20:22:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 1,000 ms
コード長 605 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 11,580 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-09-30 17:06:53
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,136 KB
testcase_01 AC 84 ms
15,076 KB
testcase_02 AC 82 ms
15,108 KB
testcase_03 AC 86 ms
15,284 KB
testcase_04 AC 83 ms
15,116 KB
testcase_05 AC 82 ms
15,156 KB
testcase_06 AC 84 ms
15,264 KB
testcase_07 AC 83 ms
15,260 KB
testcase_08 AC 82 ms
15,036 KB
testcase_09 AC 83 ms
15,004 KB
testcase_10 AC 83 ms
15,136 KB
testcase_11 AC 83 ms
15,280 KB
testcase_12 AC 82 ms
15,156 KB
testcase_13 AC 85 ms
15,224 KB
testcase_14 AC 83 ms
15,316 KB
testcase_15 AC 83 ms
15,160 KB
testcase_16 AC 83 ms
15,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Beans
    attr_reader :k, :n, :f, :a

    def initialize(k: 0, n: 0, f: 0, a: [])
        @k, @n, @f, @a = k, n, f, a
    end

    def datainput
        begin
            @k, @n, @f = gets.chomp.split.map { |v| Integer(v) }
            @a = gets.chomp.split.map { |v| Integer(v) }
        rescue
            
        end
    end

    def remaining_beans(k, n, a)
        r = k * n - a.inject(:+)
        (r < 0)? -1 : r
    end

    def dataoutput
        puts remaining_beans(@k, @n, @a)
    end

    def run
        datainput
        dataoutput
    end
end

if $0 == __FILE__
    Beans.new.run
end
0