이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long M = Long.parseLong(st.nextToken());
long [] a, b;
a = new long[N];
b = new long[N];
st = new StringTokenizer(br.readLine());
StringTokenizer st1 = new StringTokenizer(br.readLine());
for (int i=0;i<N;i++) {
a[i] = Long.parseLong(st.nextToken());
b[i] = Long.parseLong(st1.nextToken());
}
pw.println(bs(a, b, N, M));
pw.close();
br.close();
}
public static boolean f(long [] a, long [] b, int N, long M, long mid) {
long ans = 0;
for (int i=0;i<a.length;i++) {
if (a[i]>b[i]) {
long nC = mid/a[i];
if (mid%a[i]>0) nC++;
//long nC = Math.min(M, 1);
nC = Math.min(nC, M);
ans+=nC;
long remain = Math.max(mid-nC*a[i], 0);
long toAdd = remain/b[i];
if (remain%b[i]>0) toAdd++;
ans+=toAdd;
} else {
long toAdd = mid/b[i];
if (mid%b[i]>0) toAdd++;
ans+=toAdd;
}
}
return ans<=M*N;
}
public static long bs(long [] a, long [] b, int N, long M) {
long ans = 0;
long lo = 0;
long hi = (long)1e18;
while (lo<=hi) {
long mid = (lo+hi)/2;
if (f(a, b, N, M, mid)) {
ans = mid;
lo = mid+1;
} else {
hi = Math.max(mid-1, 1);
}
}
return ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |