結果

問題 No.143 豆
ユーザー yu0912
提出日時 2020-07-23 13:30:45
言語 JavaScript
(node v23.5.0)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 852 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-07-23 11:33:37
合計ジャッジ時間 2,016 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(
  input = `17 40 74
13 4 2 86 36 67 47 9 9 38 4 52 30 85 45 32 52 28 56 71 34 24 41 60 90 12 7 59 51 47 90 27 42 94 23 69 73 75 96 70 77 74 19 22 75 65 50 92 67 57 13 63 70 67 3 58 55 1 50 37 64 80 25 29 2 99 25 51 99 63 48 56 46 97
`
) {
  let lines = input.split('\n');

  let [numBeansPerPack, numPacks, numPeople] = lines[0]
    .split(' ')
    .map((val) => parseInt(val));

  let ages = lines[1].split(' ').map((val) => parseInt(val));

  let result = ages.reduce((numBeans, age) => {
    return numBeans - age;
  }, numBeansPerPack * numPacks);

  if (result < 0) {
    return '-1';
  } else {
    return `${result}`;
  }
}

const { readFileSync, existsSync } = require('fs');
const stdin = '/dev/stdin';

if (existsSync(stdin)) {
  const input = readFileSync(stdin, 'utf8');
  console.log(main(input));
}

module.exports = main;
0