結果
問題 | No.5 数字のブロック |
ユーザー |
|
提出日時 | 2018-04-04 02:00:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 272 ms / 5,000 ms |
コード長 | 556 bytes |
コンパイル時間 | 2,298 ms |
コンパイル使用メモリ | 76,884 KB |
実行使用メモリ | 59,132 KB |
最終ジャッジ日時 | 2024-11-18 12:16:52 |
合計ジャッジ時間 | 9,540 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
package yukicoder1_0; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); ArrayList<Integer> w = new ArrayList<Integer>(); for(int i = 0; i < N; i++) { w.add(sc.nextInt()); } Collections.sort(w); int sum = 0; int count =0; for(int i : w) { if(sum+i<= L) { sum +=i; count++; }else { break; } } System.out.println(count); } }