結果

問題 No.31 悪のミックスジュース
ユーザー scachescache
提出日時 2014-09-29 00:01:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,454 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 77,420 KB
実行使用メモリ 56,264 KB
最終ジャッジ日時 2023-08-28 19:50:54
合計ジャッジ時間 5,495 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 136 ms
53,904 KB
testcase_05 AC 137 ms
55,764 KB
testcase_06 AC 126 ms
55,740 KB
testcase_07 AC 138 ms
55,968 KB
testcase_08 AC 138 ms
55,560 KB
testcase_09 WA -
testcase_10 AC 137 ms
55,892 KB
testcase_11 WA -
testcase_12 AC 136 ms
55,780 KB
testcase_13 AC 124 ms
56,000 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));
//						break;
					}
				}
//				if(isChanged)
//					break;
			}
			
		}
		
		long res = 0;
		for(int i=0;i<c.length;i++)
			res += c[i] * liter[i];
		
		System.out.println(res);
	}

}
0