atishey's blog

By atishey, history, 5 years ago, In English

You will be given two sets of integers. Let's call them set A and set B. Set A contains n elements and set B contains m elements. You have to remove k1 elements from set A and k2 elements from set B so that of the remaining values no integer in set B is a multiple of any integer in set A. k1 should be in the range [0, n] and k2 in the range [0, m].

You have to find the value of (k1 + k2) such that (k1 + k2) is as low as possible. P is a multiple of Q if there is some integer K such that P = K * Q.

Suppose set A is {2, 3, 4, 5} and set B is {6, 7, 8, 9}. By removing 2 and 3 from A and 8 from B, we get the sets {4, 5} and {6, 7, 9}. Here none of the integers 6, 7 or 9 is a multiple of 4 or 5.

So for this case the answer is 3 (two from set A and one from set B).

n and m will be in the range [1, 1000].

Sample Input:

4 2 3 4 5 4 6 7 8 9


3 **** Why the solution of this problem is maximum bipartite matching ? **** I have solved this question by successively removing the node which has maximum degree until all the edges are removed. Why this approach is wrong?

This question is from lightoj , link is

Read more »

  • Vote: I like it
  • +2
  • Vote: I do not like it