結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2019-01-18 23:34:39 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 948 bytes |
| コンパイル時間 | 57 ms |
| コンパイル使用メモリ | 6,688 KB |
| 実行使用メモリ | 41,716 KB |
| 最終ジャッジ日時 | 2024-10-13 00:57:59 |
| 合計ジャッジ時間 | 2,854 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 34 |
ソースコード
function main(input) {
const input_lines = input.split("\r\n");
const box_width = parseInt(input_lines[0]);
const block_num = parseInt(input_lines[1]);
let block_width_list = getLineNumArray(input_lines[2]);
let total_width = 0;
let total_count = 0;
block_width_list
.sort((a, b) => {
if (a < b) {
return -1;
} else if (b > a) {
return 1;
} else {
return 0;
}
})
.forEach(block_width => {
if (total_width + block_width <= box_width) {
total_count++;
total_width += block_width;
}
});
console.log(total_count);
}
function getLineNumArray(line) {
const line_str_array = line.split(" ");
let line_array = [];
line_str_array.forEach(num_str => {
line_array.push(parseInt(num_str));
});
return line_array;
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main(require("fs").readFileSync("./files/yuki.txt", "utf8"));