4 条题解
-
0
``` package A; import java.io.*; public class Main { static int[] b; static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static int Int() throws Exception{ st.nextToken(); return (int)st.nval; } public static void main(String[] args) throws Exception{ int t = Int(); while (t-- > 0){ int n = Int(); int k = Int(); b = new int[n]; int[] add = new int[n + 1];//a前n项和 for (int i = 0; i < n; i++) { add[i + 1] = add[i] + Int(); } for (int i = 0; i < n; i++) { b[i] = Int(); } int x = Math.min(n, k); int[] b1 = new int[x];//维护一个单调数组 for (int i = 1; i < x; i++) { if(b[i] > b[b1[i - 1]]){ b1[i] = i; }else b1[i] = b1[i - 1]; } int ans = 0; if(n > k){ for (int i = 0; i < x; i++) { int temp = add[i + 1] + (k - i - 1) * b[b1[i]]; ans = Math.max(ans, temp); } }else { for (int i = 0; i < x; i++) { int temp = add[i + 1] + (k - i - 1) * b[b1[i]]; ans = Math.max(ans, temp); } } pw.println(ans); } pw.flush(); } } ```
信息
- ID
- 588
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 76
- 已通过
- 12
- 上传者