Hii, I tried the problem by using binary search for the answer trick. I basically made two arrays into the equal length and tried to use binary search to check for a value, if number of distinct pairs formed are >= given k. It fails in test case 11. Please help me to know whether the approach is correct. Thanks

problem: Problem - D - Codeforces

**Description:** Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That’s why he ordered both chandeliers that can change its color cyclically. For example: red – brown – yellow – red – brown – yellow and so on.

There are many chandeliers that differs in color set or order of colors. And the person responsible for the light made a critical mistake — they bought two different chandeliers.

Since chandeliers are different, some days they will have the same color, but some days — different. Of course, it looks poor and only annoys Vasya. As a result, at the k-th time when chandeliers will light with different colors, Vasya will become very angry and, most probably, will fire the person who bought chandeliers.

Your task is to calculate the day, when it happens (counting from the day chandeliers were installed). You can think that Vasya works every day without weekends and days off.

**code:**

```
public static void main(String[] args) {
int n = sc.ni(), m = sc.ni();
long k = sc.nl();
long[] a = new long[Math.max(n, m)];
long[] b = new long[Math.max(n, m)];
for (int i = 0; i < n; i++) {
a[i] = sc.ni();
}
for (int i = n; i < Math.max(n, m); i++) {
a[i] = a[i % n];
}
for (int i = 0; i < m; i++) {
b[i] = sc.ni();
}
for (int i = m; i < Math.max(n, m); i++) {
b[i] = b[i % m];
}
// out.println(Arrays.toString(a));
// out.println(Arrays.toString(b));
int[] diff = new int[Math.max(n, m)];
for (int i = 0; i < Math.max(n, m); i++) {
if (i > 0)
diff[i] = diff[i - 1];
if (a[i] != b[i]) {
diff[i] += 1;
}
}
long l = 1, r = (long) 1e15, ans = 0;
while (l <= r) {
long mid = l + (r - l) / 2;
if (found(diff, mid, k)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
out.println(ans);
out.close();
}
static boolean found(int[] diff, long i, long k) {
int len = diff.length;
long p1 = (i / len) * diff[len - 1];
int rem = (int) (i % len);
long p2 = (rem == 0) ? 0 : diff[rem - 1];
return (p1 + p2) >= k;
}
`
```