結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2021-11-15 23:15:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 120 ms / 5,000 ms |
コード長 | 1,100 bytes |
コンパイル時間 | 2,453 ms |
コンパイル使用メモリ | 79,520 KB |
実行使用メモリ | 40,984 KB |
最終ジャッジ日時 | 2024-12-15 07:59:46 |
合計ジャッジ時間 | 6,436 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Stream; class Main { public static void main(String[] args) { no5(); } // No.5 数字のブロック private static void no5() { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); // 箱の幅 String l; // ブロックの数 String n; // 各ブロックの幅 String block; try { l = reader.readLine(); n = reader.readLine(); block = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } int[] numbers = Stream.of(block.split(" ")).mapToInt(Integer::parseInt).sorted().toArray(); int width = Integer.parseInt(l); int max = 0; for (int i : numbers) { if (i <= width) { width -= i; max++; } else { break; }; } System.out.println(max); } }