結果

問題 No.5 数字のブロック
ユーザー FpmpAmpm
提出日時 2016-10-22 12:18:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 304 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 84,576 KB
実行使用メモリ 59,432 KB
最終ジャッジ日時 2024-11-18 10:22:21
合計ジャッジ時間 10,610 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
    	int L = sc.nextInt();
    	int N = sc.nextInt();
    	
    	Integer[] W = new Integer[N];
    	List<Integer> list = new ArrayList<>();
    	
    	for (int i = 0;i < N;i++) {
    		W[i] = Integer.valueOf(sc.nextInt());
    	}
    	Collections.addAll(list,W);
    	list.sort((s1, s2) -> s1.compareTo(s2));
    	int sum =0;
    	int count = 0;
    	for (Integer I:list) {
    		sum += I;
    		if (0 <= L - sum) count++;
    	}
    	System.out.println(count);
    	
    	
    	
	}
}
0