結果

問題 No.5 数字のブロック
ユーザー Ryota Enokido
提出日時 2018-12-12 09:48:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 511 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 74,920 KB
実行使用メモリ 58,888 KB
最終ジャッジ日時 2024-11-18 12:45:04
合計ジャッジ時間 12,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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 l = sc.nextInt();
            int n = sc.nextInt();
            int[] A = new int[n];
            for(int i=0; i<n; i++){
                A[i] = sc.nextInt();
            }
            
            for(int j=0; j<A.length-1; j++){
                for(int k=n-1; k>j; k--){
                    if(A[k] < A[k-1]){
                        int temp = A[k];
                        A[k] = A[k-1];
                        A[k-1] = temp;
                    }
                }
            }
            
            int ans = 0;
            while(ans<n){
                l -= A[ans];
                if(l<0){
                    break;
                }
                ans++;
            }
            
            System.out.println(ans);
        }
    }
0