結果

問題 No.31 悪のミックスジュース
ユーザー scachescache
提出日時 2014-09-29 00:20:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,405 bytes
コンパイル時間 2,999 ms
コンパイル使用メモリ 77,624 KB
実行使用メモリ 57,764 KB
最終ジャッジ日時 2023-08-28 19:52:21
合計ジャッジ時間 6,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 138 ms
55,476 KB
testcase_05 AC 138 ms
56,008 KB
testcase_06 AC 127 ms
55,756 KB
testcase_07 AC 137 ms
55,836 KB
testcase_08 AC 137 ms
55,716 KB
testcase_09 WA -
testcase_10 AC 135 ms
55,648 KB
testcase_11 WA -
testcase_12 AC 137 ms
55,644 KB
testcase_13 AC 124 ms
55,720 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.util.Arrays;
import java.util.Scanner;

/**
 * yukicoder no.31
 * @author scache
 *
 */
public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long v = sc.nextLong();
		long[] c = new long[n];
		for(int i=0;i<n;i++)
			c[i] = sc.nextLong();
		solve(v, c);
	}

	public void solve(long v, long[] c) {
		
		long[] liter = new long[c.length];
		Arrays.fill(liter, 1);
		liter[0] = Math.max(v-c.length+1, 1);
		
		long[] costSum = new long[c.length];
		costSum[0] = c[0];
		for(int i=1;i<c.length;i++)
			costSum[i] = costSum[i-1]+c[i];
		
		boolean isChanged = true;
		while(isChanged){
			isChanged = false;
			for(int i=0;i<c.length;i++){
				long curTotal = liter[i]; 
				long curCost = c[i] * liter[i];
				for(int j=i+1;j<c.length;j++){
					curTotal += liter[j];
					curCost += c[j]*liter[j];
					
					if(curCost > c[i]*(curTotal%(j-i+1)) + costSum[j]*(curTotal/(j-i+1))){
						liter[i] = curTotal%(j-i+1)+curTotal/(j-i+1);
						Arrays.fill(liter, i+1, j+1, curTotal/(j-i+1));
						isChanged = true;
						curCost = c[i]*(curTotal%(j-i+1)) + costSum[j]*(curTotal/(j-i+1));
//						System.out.println(Arrays.toString(liter));
					}
				}
			}
			
		}
		
		long res = 0;
		for(int i=0;i<c.length;i++)
			res += c[i] * liter[i];
		
		System.out.println(res);
	}

}
0