結果

問題 No.156 キャンディー・ボックス
ユーザー Ryota Enokido
提出日時 2018-12-11 10:54:09
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 74,548 KB
実行使用メモリ 54,532 KB
最終ジャッジ日時 2024-09-19 19:48:30
合計ジャッジ時間 7,247 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other AC * 2 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

 import java.util.Scanner;
 import java.lang.Math;
 
  public class Main {
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
 
          int N = sc.nextInt();
          int M = sc.nextInt();
          int ans = 0;
          int[] C = new int[N];
          for(int i=0; i<N; i++){
              C[i] = sc.nextInt();
          }
          
          //boublesort
          for(int j=0; j<C.length-1; j++){
              for(int k=N-1; k>j; k--){
                  if(C[k] < C[k-1]){
                      int temp = C[k];
                      C[k] = C[k-1];
                      C[k-1] = temp;
                  }
              }
          }
          
          int l=0;
          while(M>0){
              M -= C[l];
              if(M<0){
                  break;
              }
              ans++;
              l++;
              System.out.println(M);
          }
          System.out.println(ans);
      }
  }
0