結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2023-04-25 18:29:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 220 ms / 5,000 ms |
コード長 | 1,234 bytes |
コンパイル時間 | 3,032 ms |
コンパイル使用メモリ | 75,588 KB |
実行使用メモリ | 55,560 KB |
最終ジャッジ日時 | 2024-11-14 14:38:03 |
合計ジャッジ時間 | 9,545 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { // 入力を受け取る Scanner scan = new Scanner(System.in); String strL = scan.nextLine(); String strN = scan.nextLine(); String strW = scan.nextLine(); scan.close(); // 値を受け取る int boxLength = Integer.parseInt(strL); int blockNum = Integer.parseInt(strN); String[] arrW = strW.split(" "); int[] blockWidths = new int[arrW.length]; for(int i = 0; i < arrW.length; i++) { blockWidths[i] = Integer.parseInt(arrW[i]); } // 計算 int totalBlockWidths = 0; int count = 0; Arrays.sort(blockWidths); for (int i = 0; i < blockWidths.length; i++) { // ブロックを小さい順に箱へ足していく totalBlockWidths += blockWidths[i]; // 箱にブロックが入らなくなったときループ終了 if(boxLength < totalBlockWidths) { break; } count ++; } // 箱に入る最大のブロック個数を出力 System.out.println(count); } }