I was trying out this problem: http://codeforces.me/contest/469/problem/D Although I thought this is a question of matching in graph. I tried doing it other way round. What I have done till now in this is: distribute elements in set A and check whether rest can be in set B or not. If not then change the above, i.e. distribute in B and then go for A. In each I will also check in the end if every element is now there in some set or not.
I know I am making mistake here and missing some test cases like the cases in which some elements can be there in either of the set and answer may be YES by distributing some elements in B which I initially kept in A. But I am unable to figure out how I should start thinking with the matching? What should be the approach for that? Not only for this question, for any other question if one could answer, that will be really helpful.
Shouldn't it be b-(a-x) int he first point? For any point x belonging to A, and thus a-x also, the condition that it can belong to B is (b-x) and b-(a-x) must be in B.
That's right, I fixed it.
As a side note, this problem can also be solved by a Maximum Matching algorithm, but given the constraints of the problem, it wouldn't run in time.