結果
| 問題 | 
                            No.198 キャンディー・ボックス2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kenkoooo
                         | 
                    
| 提出日時 | 2015-04-29 00:27:43 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,060 bytes | 
| コンパイル時間 | 2,316 ms | 
| コンパイル使用メモリ | 77,632 KB | 
| 実行使用メモリ | 41,688 KB | 
| 最終ジャッジ日時 | 2024-07-05 05:24:31 | 
| 合計ジャッジ時間 | 6,901 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 WA * 4 | 
ソースコード
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[j];
				}
				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);
	}
}
            
            
            
        
            
kenkoooo