-
Notifications
You must be signed in to change notification settings - Fork 14
/
q11011.java
50 lines (41 loc) · 1.24 KB
/
q11011.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.*;
public class Main {
public static int N, K;
public static long[] dp, a, b;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
a = new long[N];
b = new long[N];
dp = new long[N];
st = new StringTokenizer(br.readLine());
for (int i=0;i<N;i++) {
a[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for (int i=0;i<N;i++) {
b[i] = Integer.parseInt(st.nextToken());
}
dnc(0, N-1, 0, N-1);
System.out.println(answer);
}
public static long answer;
public static void dnc (int l, int r, int dl, int dr) {
int mid = l + r >> 1;
int idx = -1;
long value = -1;
for (int i=Math.max(dl,mid-K);i<=mid&&i<=dr;i++) {
if (value < (mid - i) * a[mid] + b[i]) {
value = (mid - i) * a[mid] + b[i];
idx = i;
}
}
answer = Math.max(answer, value);
if (l == r) return;
dnc(l, mid, dl, idx);
dnc(mid+1, r, idx, dr);
}
}