結果

問題 No.198 キャンディー・ボックス2
ユーザー kenkooookenkoooo
提出日時 2015-04-29 00:20:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 3,083 ms
コンパイル使用メモリ 79,332 KB
実行使用メモリ 56,160 KB
最終ジャッジ日時 2023-09-18 14:34:31
合計ジャッジ時間 8,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,112 KB
testcase_01 AC 128 ms
55,824 KB
testcase_02 AC 127 ms
55,748 KB
testcase_03 AC 126 ms
55,940 KB
testcase_04 AC 127 ms
55,528 KB
testcase_05 AC 126 ms
55,380 KB
testcase_06 AC 128 ms
55,436 KB
testcase_07 AC 126 ms
55,596 KB
testcase_08 AC 129 ms
55,840 KB
testcase_09 AC 128 ms
56,160 KB
testcase_10 AC 126 ms
55,984 KB
testcase_11 AC 128 ms
55,596 KB
testcase_12 AC 127 ms
55,796 KB
testcase_13 AC 128 ms
55,668 KB
testcase_14 AC 126 ms
55,916 KB
testcase_15 AC 128 ms
55,544 KB
testcase_16 AC 125 ms
55,912 KB
testcase_17 AC 126 ms
55,776 KB
testcase_18 AC 126 ms
55,812 KB
testcase_19 AC 127 ms
55,812 KB
testcase_20 AC 129 ms
55,680 KB
testcase_21 WA -
testcase_22 AC 129 ms
56,120 KB
testcase_23 WA -
testcase_24 AC 131 ms
55,432 KB
testcase_25 WA -
testcase_26 AC 127 ms
56,156 KB
testcase_27 AC 129 ms
55,732 KB
testcase_28 WA -
testcase_29 AC 128 ms
55,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int B = sc.nextInt();
		int N = sc.nextInt();
		int[] C = new int[N];
		for (int i = 0; i < C.length; i++) {
			C[i] = sc.nextInt();
		}
		sc.close();

		long min = Long.MAX_VALUE;
		for (int i = 0; i < C.length; i++) {
			int V = C[i];
			long stock = B;
			long ope = 0;
			for (int j = 0; j < C.length; j++) {
				// 取り上げ
				stock += Math.max(0, C[j] - V);
				ope += Math.max(0, C[j] - V);
			}
			for (int j = 0; j < C.length; j++) {
				// 配る
				stock -= Math.max(0, V - C[j]);
				ope += Math.max(0, V - C[j]);
			}
			if (stock < 0) {
				long sum = B;
				for (int j = 0; j < C.length; j++) {
					sum += C[i];
				}
				if (stock + sum >= 0) {
					long need = Math.abs(stock);
					if (need % N == 0) {
						ope += need;
					} else {
						ope += need / N * N;
						ope += N;
					}
				} else {
					ope = Long.MAX_VALUE;
				}
			}
			min = Math.min(min, ope);
		}
		System.out.println(min);

	}

}
0