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);