結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2022-07-28 18:30:56 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 353 ms / 5,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 1,989 ms |
コンパイル使用メモリ | 76,556 KB |
実行使用メモリ | 39,520 KB |
最終ジャッジ日時 | 2024-07-18 09:08:15 |
合計ジャッジ時間 | 6,903 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(br.readLine()); int N = Integer.parseInt(br.readLine()); String[] input = br.readLine().split(" "); int[] W = new int[N]; for(int i = 0; i < N; i++) W[i] = Integer.parseInt(input[i]); for(int i = 0; i < N - 1; i++) { for(int j = i + 1; j < N; j++) { if(W[i] > W[j]) { int x = W[i]; W[i] = W[j]; W[j] = x; } } } int sum = 0; int count = 0; for(int i = 0; i < N; i++) { if(sum + W[i] <= L) { sum += W[i]; count++; } } System.out.println(count); } }