結果

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

ソースコード

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(ans);
      }
  }
0