結果
問題 | No.5 数字のブロック |
ユーザー | hhgfhn1 |
提出日時 | 2018-08-20 23:49:03 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 264 ms / 5,000 ms |
コード長 | 618 bytes |
コンパイル時間 | 2,296 ms |
コンパイル使用メモリ | 76,164 KB |
実行使用メモリ | 59,116 KB |
最終ジャッジ日時 | 2024-11-18 12:33:42 |
合計ジャッジ時間 | 9,124 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; class sampleA { public static void main(String args[]) { Scanner scan = new Scanner(System.in); int l = scan.nextInt(); int n = scan.nextInt(); int answer = 0; List<Integer> blocksLength = new ArrayList<>(); int sumW = 0; for (int i = 0; i < n; i++) { blocksLength.add(scan.nextInt()); } scan.close(); Collections.sort(blocksLength); for (int w : blocksLength) { if (sumW + w <= l) { sumW += w; answer++; } else { break; } } System.out.print(answer); } }