結果
問題 | No.156 キャンディー・ボックス |
ユーザー |
![]() |
提出日時 | 2016-03-23 15:44:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 128 ms / 2,000 ms |
コード長 | 731 bytes |
コンパイル時間 | 3,959 ms |
コンパイル使用メモリ | 74,816 KB |
実行使用メモリ | 41,492 KB |
最終ジャッジ日時 | 2024-07-05 15:48:03 |
合計ジャッジ時間 | 8,362 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.Scanner; public class yukicoder_156 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); int m = stdIn.nextInt(); int[] box = new int[n]; for (int i = 0; i < n; i++) { box[i] = stdIn.nextInt(); } for (int i = 1; i <= box.length; i++) { for (int j = 0; j < box.length - 1; j++) { if (box[j] > box[j+1]) { int t; t = box[j]; box[j] = box[j+1]; box[j+1] = t; } } } int candy = 0, i = 0; for(i = 0; i < box.length; i++) { candy += box[i]; if (candy > m) { break; } } System.out.println(i); } }