結果
問題 |
No.31 悪のミックスジュース
|
ユーザー |
|
提出日時 | 2014-09-29 00:30:54 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,406 bytes |
コンパイル時間 | 2,578 ms |
コンパイル使用メモリ | 77,176 KB |
実行使用メモリ | 54,292 KB |
最終ジャッジ日時 | 2024-12-30 06:39:05 |
合計ジャッジ時間 | 6,299 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 9 |
ソースコード
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); } }