結果

問題 No.5 数字のブロック
ユーザー yu0912
提出日時 2020-07-23 14:04:58
言語 JavaScript
(node v23.5.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-06-23 17:33:19
合計ジャッジ時間 3,511 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input = ``) {
  let lines = input.split('\n');

  let [boxSize] = lines[0].split(' ').map((val) => parseInt(val));
  let blockSizes = lines[2]
    .split(' ')
    .map((val) => parseInt(val))
    .sort((a, b) => a - b);

  let currentSize = 0;
  let numBoxes = 0;

  blockSizes.forEach((blockSize) => {
    if (currentSize + blockSize <= boxSize) {
      numBoxes += 1;
      currentSize += blockSize;
    }
  });

  return `${numBoxes}`;
}

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