結果

問題 No.143 豆
ユーザー yu0912yu0912
提出日時 2020-07-23 13:30:45
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 79 ms / 1,000 ms
コード長 852 bytes
コンパイル時間 26 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 44,004 KB
最終ジャッジ日時 2023-09-30 17:52:51
合計ジャッジ時間 2,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
41,832 KB
testcase_01 AC 77 ms
41,748 KB
testcase_02 AC 77 ms
41,924 KB
testcase_03 AC 76 ms
42,016 KB
testcase_04 AC 76 ms
41,964 KB
testcase_05 AC 77 ms
41,920 KB
testcase_06 AC 75 ms
41,980 KB
testcase_07 AC 76 ms
41,940 KB
testcase_08 AC 77 ms
41,848 KB
testcase_09 AC 77 ms
41,740 KB
testcase_10 AC 78 ms
41,884 KB
testcase_11 AC 77 ms
42,216 KB
testcase_12 AC 77 ms
42,016 KB
testcase_13 AC 77 ms
41,852 KB
testcase_14 AC 77 ms
41,972 KB
testcase_15 AC 79 ms
44,004 KB
testcase_16 AC 77 ms
41,880 KB
権限があれば一括ダウンロードができます

ソースコード

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