結果

問題 No.5 数字のブロック
ユーザー AoiroFukurou
提出日時 2016-05-19 13:50:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 382 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 3,510 ms
コンパイル使用メモリ 74,432 KB
実行使用メモリ 58,668 KB
最終ジャッジ日時 2024-11-18 08:36:37
合計ジャッジ時間 12,382 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class No5 {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int L = sc.nextInt();
	int N = sc.nextInt();
	int[] w = new int[N];
	int tmp = 0;
	int c = 0;
	for(int i = 0; i < w.length; i++){
		w[i] = sc.nextInt();
	}
	for(int j = 1; j < w.length; j++){
		int tmp2 = w[j];
		int i = j - 1;
		while(i >= 0 && w[i] > tmp2){
			w[i + 1] = w[i];
			i--;
		}
		w[i + 1] = tmp2;
	}
	for(int i = 0; i < w.length; i++){
		if(L - tmp >= w[i]){
			tmp += w[i];
			c++;
		}else{
			break;
		}
	}
	System.out.println(c);
	sc.close();
}
}
0