結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,312 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 70 ms
52,064 KB
testcase_05 AC 71 ms
51,884 KB
testcase_06 AC 44 ms
49,372 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 72 ms
52,052 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 45 ms
49,300 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


class Main {
    static final long I=1L<<60;
    static final int W=10000;
    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