結果

問題 No.5 数字のブロック
ユーザー intercept6
提出日時 2020-08-13 15:51:45
言語 TypeScript
(5.7.2)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 8,927 ms
コンパイル使用メモリ 228,860 KB
実行使用メモリ 43,648 KB
最終ジャッジ日時 2024-12-31 16:18:24
合計ジャッジ時間 11,958 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import { readFileSync } from 'fs';

function reducer(accumulator: number, currentValue: number) {
  return accumulator + currentValue;
}

function Main(input: string) {
  const data = input.split('\n');

  const boxWidth = data[0].split(' ').map(Number)[0];
  const blockNumber = data[1].split(' ').map(Number)[0];
  const blocks = data[2]
    .split(' ')
    .map(Number)
    .sort((a, b) => a - b);

  for (let i = 0; i <= blockNumber; i++) {
    const current = blocks.slice(0, i);
    if (current.length === 0) {
      continue;
    }

    const sum = current.reduce(reducer);
    if (sum === boxWidth) {
      console.log(i);
    } else if (sum > boxWidth) {
      console.log(i - 1);
      return;
    }
  }
}

Main(readFileSync('/dev/stdin', 'utf8'));
0