結果

問題 No.5 数字のブロック
ユーザー bigbear90560
提出日時 2015-07-03 22:09:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 3,849 ms
コンパイル使用メモリ 75,932 KB
実行使用メモリ 48,152 KB
最終ジャッジ日時 2024-11-17 22:58:24
合計ジャッジ時間 10,778 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

/**
 * No.5 数字のブロック
 */
public class NumberBlock {

	public static void main(String[] args) {

		// 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();	// 幅
        int b = sc.nextInt();	// ブロック数
    	int[] c = new int[b];

        for (int i=0;i<b;i++) {
        	c[i] = sc.nextInt();	// ブロック幅
        }
        
        // 配列をソート
        Arrays.sort(c);
        
        int resWidth = 0;
        int resCount = 0;
        for (int n : c) {
        	resWidth += n;
			if (a >= resWidth) {
				resCount++;
			} else {
				break;
			}
        }
        System.out.println(resCount);
	}

}
0