結果

問題 No.5 数字のブロック
コンテスト
ユーザー spring
提出日時 2019-06-12 15:37:04
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 651 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,649 ms
コンパイル使用メモリ 85,488 KB
実行使用メモリ 50,980 KB
最終ジャッジ日時 2026-04-27 00:59:03
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int box = sc.nextInt();
		int count = sc.nextInt();
		ArrayList<Integer> boxlist = new ArrayList<Integer>();
		for(int i=0;i<count;i++){
			int input = sc.nextInt();
			boxlist.add(input);
		}
		sc.close();
		Collections.sort(boxlist);
		int total=0;
		int result = 0;
		for(int k=0;box>total&&boxlist.size()>k;k++){
			total += boxlist.get(k);
			if(box>=total){
				result++;
			}else{
				break;
			}
		}
		System.out.println(result);
	}// mainmethod

} // cla
0