結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2017-03-26 14:51:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 258 ms / 5,000 ms |
コード長 | 528 bytes |
コンパイル時間 | 2,115 ms |
コンパイル使用メモリ | 74,636 KB |
実行使用メモリ | 59,316 KB |
最終ジャッジ日時 | 2024-11-18 10:58:36 |
合計ジャッジ時間 | 9,087 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.util.Scanner; import java.util.Arrays; class Block{ public static void main(String args[]){ Scanner s = new Scanner(System.in); int L = s.nextInt(); int N = s.nextInt(); int W[] = new int[N]; for(int i = 0; i < N; i++){ W[i] = s.nextInt(); } Arrays.sort(W); int sum = 0; for(int j = 0; j < N; j++){ sum += W[j]; if(sum == L){ System.out.println(j + 1); System.exit(0); }else if(sum > L){ System.out.println(j); System.exit(0); } } System.out.println(N); } }