結果

問題 No.5 数字のブロック
ユーザー jintan-aka
提出日時 2024-09-17 18:06:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-09-17 18:06:27
合計ジャッジ時間 1,972 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

# 大きな箱の幅を入力
L = int(input())

# ブロックの数を入力
N = int(input())

# 各ブロックの幅を入力(半角スペース区切り)
block_widths = list(map(int, input().split()))

# ブロックの幅を昇順にソート
block_widths.sort()

# 箱に入れられるブロックの最大数を計算
total_width = 0
max_blocks = 0

for width in block_widths:
    # 現在のブロックを追加した場合の幅の合計が箱の幅を超えない場合
    if total_width + width <= L:
        total_width += width
        max_blocks += 1
    else:
        # 箱の幅を超えたら終了
        break

# 結果を出力
print(max_blocks)
0