結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Pump0129
提出日時 2018-03-26 18:37:57
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 75,272 KB
実行使用メモリ 41,372 KB
最終ジャッジ日時 2024-06-25 06:50:43
合計ジャッジ時間 5,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no617;

import java.util.ArrayList;
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();
		
		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