結果

問題 No.617 Nafmo、買い出しに行く
ユーザー 37zigen
提出日時 2017-12-05 00:07:22
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 3,544 ms
コンパイル使用メモリ 75,444 KB
実行使用メモリ 41,440 KB
最終ジャッジ日時 2024-11-28 05:46:02
合計ジャッジ時間 6,302 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

package tmp;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		int ans = 0;
		for (int i = A.length - 1; i >= 0; --i) {
			if (ans + A[i] > K)
				continue;
			else {
				ans += A[i];
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0