結果

問題 No.5 数字のブロック
ユーザー YukimotoPG
提出日時 2019-02-13 19:33:39
言語 Java
(openjdk 23)
結果
AC  
実行時間 245 ms / 5,000 ms
コード長 400 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 75,824 KB
実行使用メモリ 59,840 KB
最終ジャッジ日時 2024-11-18 12:56:28
合計ジャッジ時間 8,767 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int l = sc.nextInt();
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = sc.nextInt();
		Arrays.sort(ar);
		int ans = 0;
		for (int i=0; i<n; i++) {
			if (l-ar[i] >= 0) {
				l -= ar[i];
				ans++;
			}
		}
		System.out.println(ans);
		
	}
}
0