結果

問題 No.198 キャンディー・ボックス2
ユーザー kenkooookenkoooo
提出日時 2015-04-29 00:35:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 861 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 73,844 KB
実行使用メモリ 57,896 KB
最終ジャッジ日時 2023-08-10 07:29:04
合計ジャッジ時間 7,095 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
57,896 KB
testcase_01 AC 124 ms
55,468 KB
testcase_02 AC 123 ms
55,460 KB
testcase_03 AC 122 ms
56,100 KB
testcase_04 AC 125 ms
55,768 KB
testcase_05 AC 126 ms
55,880 KB
testcase_06 AC 124 ms
55,816 KB
testcase_07 AC 125 ms
55,916 KB
testcase_08 AC 124 ms
55,740 KB
testcase_09 AC 122 ms
55,964 KB
testcase_10 AC 123 ms
56,144 KB
testcase_11 AC 122 ms
55,672 KB
testcase_12 AC 125 ms
56,224 KB
testcase_13 AC 125 ms
55,780 KB
testcase_14 AC 125 ms
56,152 KB
testcase_15 AC 122 ms
55,708 KB
testcase_16 AC 126 ms
55,840 KB
testcase_17 AC 127 ms
56,196 KB
testcase_18 AC 129 ms
55,796 KB
testcase_19 AC 129 ms
56,204 KB
testcase_20 AC 123 ms
56,248 KB
testcase_21 AC 124 ms
55,972 KB
testcase_22 AC 128 ms
56,124 KB
testcase_23 AC 124 ms
55,936 KB
testcase_24 AC 124 ms
55,812 KB
testcase_25 AC 126 ms
56,112 KB
testcase_26 AC 125 ms
55,976 KB
testcase_27 AC 127 ms
56,116 KB
testcase_28 AC 126 ms
55,724 KB
testcase_29 AC 127 ms
55,856 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++) {
			long V = C[i];

			long sum = B;
			for (int j = 0; j < C.length; j++) {
				sum += C[j];
			}
			if (sum < N * V) {
				V = sum / N;
			}

			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]);
			}
			min = Math.min(min, ope);

		}
		System.out.println(min);

	}

}
0