結果

問題 No.5 数字のブロック
ユーザー AAAR Salmon
提出日時 2021-04-02 14:34:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 292 ms / 5,000 ms
コード長 446 bytes
コンパイル時間 6,472 ms
コンパイル使用メモリ 74,556 KB
実行使用メモリ 47,728 KB
最終ジャッジ日時 2024-12-23 09:18:27
合計ジャッジ時間 12,480 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class problem1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L, N;
		L = sc.nextInt();
		N = sc.nextInt();
		int[] W = new int[N];
		for (int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
		}
		Arrays.sort(W);

		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (L >= W[i]) {
				L -= W[i];
				ans++;
			}
		}
		System.out.println(ans);
	}
}
0