Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Rocky {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int numTests = sc.nextInt();
- for (int testNumber = 0; testNumber < numTests; testNumber++) {
- int m = sc.nextInt();
- int n = sc.nextInt();
- int k = sc.nextInt();
- int[] t = new int[m];
- int[] p = new int[m];
- for (int i = 0; i < m; i++)
- t[i] = sc.nextInt();
- for (int i = 0; i < m; i++)
- p[i] = sc.nextInt();
- int l = 0;
- int r = t[0] + (k - 1) * p[0];
- int[] q = new int[m];
- while (l < r) {
- int mm = (l + r) / 2;
- for (int i = 0; i < m; i++) {
- if (mm < t[i])
- q[i] = 0;
- else
- q[i] = (mm - t[i]) / p[i] + 1;
- }
- Arrays.sort(q);
- long cur = 0;
- for (int i = m - 1; i >= 0 && i >= m - n; i--)
- cur += q[i];
- if (cur >= k)
- r = mm;
- else
- l = mm + 1;
- }
- System.out.println(l);
- }
- }
- }
Add Comment
Please, Sign In to add comment