結果
問題 | No.5 数字のブロック |
ユーザー | Shun_PI |
提出日時 | 2017-05-11 00:09:23 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 469 ms / 5,000 ms |
コード長 | 601 bytes |
コンパイル時間 | 2,130 ms |
コンパイル使用メモリ | 74,724 KB |
実行使用メモリ | 58,872 KB |
最終ジャッジ日時 | 2024-11-18 11:04:42 |
合計ジャッジ時間 | 11,673 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
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(); int[] W = new int[N]; for(int i=0; i<N; i++) { W[i] = sc.nextInt(); } for(int i=0; i<N-1; i++) { for(int j=0; j<N-i-1; j++) { if(W[j] > W[j+1]) { int temp = W[j+1]; W[j+1] = W[j]; W[j] = temp; } } } int sum = 0; int cnt = 0; for(int i=0; i<N; i++) { if(sum + W[i] > L) { break; } else { sum += W[i]; cnt++; } } System.out.println(cnt); } }