結果

問題 No.5 数字のブロック
ユーザー koukonko
提出日時 2015-12-16 21:23:55
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 76,536 KB
実行使用メモリ 39,952 KB
最終ジャッジ日時 2024-09-16 05:57:28
合計ジャッジ時間 5,546 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

		try {
			int L = Integer.parseInt(read.readLine());
			int N = Integer.parseInt(read.readLine());

			String[] box = read.readLine().split(" ");
			int[] w = new int[N];
			for (int i = 0; i < N; ++i) {
				w[i] = Integer.parseInt(box[i]);
			}

			int total = 0, ans = 0;
			for (int i = 0; i < N - 1; ++i) {
				for (int j = i + 1; j < N; ++j) {
					if (w[i] > w[j]) {
						int sw = w[i];
						w[i] = w[j];
						w[j] = sw;
					}
				}
				total += w[i];
				if (total <= L) {
					++ans;
				} else {
					break;
				}

			}
			System.out.println(ans);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0