結果

問題 No.31 悪のミックスジュース
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-05 13:04:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,499 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 53,176 KB
最終ジャッジ日時 2023-08-24 20:16:36
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
51,628 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 102 ms
52,188 KB
testcase_05 AC 99 ms
52,420 KB
testcase_06 AC 57 ms
50,400 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 100 ms
52,256 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 57 ms
50,448 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static final long I=1L<<62;
    static final int W=100000;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long v=sc.nextInt();
        long[]c=new long[n];
        for(int i=0;i<n;++i)c[i]=sc.nextInt();
        for(int i=1;i<n;++i)c[i]+=c[i-1];
        v-=n;
        long[]dp=new long[W];
        Arrays.fill(dp,I);
        dp[0]=0;
        for(int i=0;i<n;++i)
            for(int j=0;j<W-(i+1);++j)
                dp[j+i+1]=Math.min(dp[j+i+1],dp[j]+c[i]);
        double min=1.0/0.0;
        int minind=-1;
        for(int i=0;i<n;++i){
            double r=(i+1)/(double)c[i];
            if(min>r){
                min=r;
                minind=i;
            }
        }
        long ans=I;
        for(int i=0;i<W;++i){
            long cor=Math.max(0,(v-i+minind)/(minind+1)*c[minind]);
            ans=Math.min(ans,dp[i]+cor);
        }
        ans+=c[n-1];
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
0