結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Pump0129Pump0129
提出日時 2018-03-26 18:40:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 73,840 KB
実行使用メモリ 57,576 KB
最終ジャッジ日時 2023-09-07 12:46:44
合計ジャッジ時間 5,984 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,564 KB
testcase_01 AC 119 ms
55,596 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 118 ms
55,908 KB
testcase_06 AC 123 ms
55,624 KB
testcase_07 AC 119 ms
55,652 KB
testcase_08 AC 117 ms
55,836 KB
testcase_09 AC 120 ms
55,612 KB
testcase_10 AC 114 ms
55,968 KB
testcase_11 AC 115 ms
55,544 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 118 ms
55,764 KB
testcase_16 AC 119 ms
55,576 KB
testcase_17 AC 119 ms
55,776 KB
testcase_18 AC 118 ms
55,492 KB
testcase_19 AC 122 ms
55,600 KB
testcase_20 AC 121 ms
55,584 KB
testcase_21 AC 123 ms
55,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no617;

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String line = scan.nextLine();
		int count = Integer.parseInt(line.split(" ")[0]);
		int maxweight = Integer.parseInt(line.split(" ")[1]);
		
		List<Integer> stocks = new ArrayList<Integer>();
		
		for (int i = 0; i < count; i++) {
			stocks.add(Integer.parseInt(scan.nextLine()));
		}
		
		scan.close();
		
		Collections.sort(stocks);
		
		int cw = 0;
		
		for (int i = stocks.size() - 1; 0 <= i; i--) {
			if (cw + stocks.get(i) <= maxweight) {
				cw += stocks.get(i);
			}
		}
		
		System.out.println(cw);
	}
}
0