4 条题解

  • 0
    @ 2024-1-7 14:58:07
    import java.util.*;
    import java.io.*;
    public class Main {
    
        static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        public static void main(String[] args)throws Exception {
            int q = Int();
            while (q-- > 0) {
                int n = Int();
                int k = Int();
                int[] a = new int[n];
                int[] b = new int[n];
                a[0]=Int();
                for (int i = 1; i < n; i++) a[i] =a[i-1]+ Int();
                b[0]=Int();
                int max2=b[0];
                for (int i = 1; i < n; i++) max2=b[i] = Math.max(Int(),max2);
                int j=Math.min(k,a.length);
                int max=0;
                for(int i=j-1;i>=0;i--){
                    int sum=0;
                    int m=k-i-1;
                    sum+=a[i];
                    if(m==0)max= Math.max(sum,max);
                    else {
                        sum += b[i] * m;
                        max = Math.max(sum, max);
                    }
                }
                pw.println(max);
            }
            pw.flush();
        }
        private static int Int() throws Exception{
            st.nextToken();
            return (int)st.nval;
        }
    }
    

    信息

    ID
    588
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    76
    已通过
    12
    上传者