結果

問題 No.5 数字のブロック
ユーザー maru
提出日時 2017-09-24 01:34:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 3,707 ms
コンパイル使用メモリ 81,484 KB
実行使用メモリ 47,788 KB
最終ジャッジ日時 2024-11-18 11:46:18
合計ジャッジ時間 11,117 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Ellen {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int maxW = scan.nextInt();
		int num = scan.nextInt();
		int[] wArray = new int[num];

		List<Integer> list = new ArrayList<>();
		//Arrays.sort(widthArray);
		for(int i =0; i<wArray.length; i++) {
			wArray[i] = scan.nextInt();





		}
		Arrays.sort(wArray);
		int all =0;
		int count =0;
		for(int n : wArray) {
			if(all + n<= maxW) {
				all+=n;
				count++;
			}
		}
		System.out.println(count);
	}

}
0