結果

問題 No.143 豆
ユーザー peta727
提出日時 2016-05-13 22:15:06
言語 PHP
(843.2)
結果
AC  
実行時間 42 ms / 1,000 ms
コード長 1,541 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 32,400 KB
実行使用メモリ 32,532 KB
最終ジャッジ日時 2024-07-23 10:30:27
合計ジャッジ時間 1,484 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
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