結果

問題 No.143 豆
ユーザー peta727peta727
提出日時 2016-05-13 22:15:06
言語 PHP
(8.2.11)
結果
AC  
実行時間 17 ms / 1,000 ms
コード長 1,541 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 18,636 KB
実行使用メモリ 18,868 KB
最終ジャッジ日時 2023-09-30 16:45:39
合計ジャッジ時間 1,217 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,864 KB
testcase_01 AC 16 ms
18,768 KB
testcase_02 AC 16 ms
18,816 KB
testcase_03 AC 16 ms
18,852 KB
testcase_04 AC 16 ms
18,868 KB
testcase_05 AC 16 ms
18,808 KB
testcase_06 AC 16 ms
18,648 KB
testcase_07 AC 16 ms
18,816 KB
testcase_08 AC 17 ms
18,644 KB
testcase_09 AC 16 ms
18,856 KB
testcase_10 AC 16 ms
18,644 KB
testcase_11 AC 16 ms
18,644 KB
testcase_12 AC 16 ms
18,852 KB
testcase_13 AC 16 ms
18,828 KB
testcase_14 AC 16 ms
18,864 KB
testcase_15 AC 15 ms
18,848 KB
testcase_16 AC 16 ms
18,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

namespace Coder;

class IO
{
    private $raw = [];
    private $count = 0;
    private $pointer = 0;

    /*
     * デリミタで区切った文字列を取得する
     * @param string
     * @return string
     */
    public function next($del = ' ') {
        if ($this->pointer >= $this->count) {
            $this->raw = explode("{$del}", trim(fgets(STDIN)));
            $this->count = count($this->raw);
            $this->pointer = 0;
        }
        $result = $this->raw[$this->pointer];
        $this->pointer++;
        return $result;
    }
    /*
     * 次にまだ文字列があるかを調べる
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    /*
     * int型で文字列を取り出す
     * @return int
     */
    public function nextInt($del = ' ') {
        return (int)$this->next($del);
    }
    /*
     * double型で文字列を取り出す
     * @return double
     */
    public function nextDouble($del = ' ') {
        return (double)$this->next($del);
    }
    /*
     * 改行を末尾に追加して出力する
     * @param string
     */
    public static function out ($str = '') {
        echo $str . PHP_EOL;
    }
}

$io = new IO();

$k = $io->nextInt();
$n = $io->nextInt();
$f = $io->nextInt();
$list = [];
for ($i = 0; $i < $f; $i++) {
    $list[] = $io->nextInt();
}
$total = $k * $n;

foreach ($list as $v) {
    $total -= $v;
    if ($total < 0) {
        $total = -1;
        break;
    }
}
$io->out($total);
0