結果

問題 No.31 悪のミックスジュース
ユーザー scachescache
提出日時 2014-09-29 00:07:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 3,290 ms
コンパイル使用メモリ 73,100 KB
実行使用メモリ 58,024 KB
最終ジャッジ日時 2023-08-28 19:51:30
合計ジャッジ時間 6,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 126 ms
56,276 KB
testcase_05 AC 126 ms
55,836 KB
testcase_06 AC 114 ms
55,720 KB
testcase_07 AC 127 ms
55,876 KB
testcase_08 AC 129 ms
55,728 KB
testcase_09 WA -
testcase_10 AC 127 ms
55,960 KB
testcase_11 WA -
testcase_12 AC 127 ms
55,868 KB
testcase_13 AC 116 ms
55,948 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