This problem has many ways to solve it,here I want to write something about my greedy solution,thouth I haven't confirm it.
My solution is,firstly,sort the number sequence P,then start from the smallest one (suppose b>a),if it can be divided into B set with a number which hasn't been used,just put it into B set,otherwise if it can be divided into A set with a number which hasn't been used,just put it into A set,or puts NO and ends the program.
I hope to know someone who has the same idea with me and confirm it and share my solution with you!!!
My solution also used 2 sets:
http://codeforces.me/contest/468/submission/7875703
Firstly, put all elements into set A.
Secondly, put elements which are not suitable in set A into set B.
Finally, erase elements x and b-x in set B (or set A) and do some more simple work.
Hope that help you!
It's also a nice solution.
thank you
Your greedy idea is correct and nice. But in CF's tutorial it is mentioned that this problem can be solved by using a 2SAT approach. Does anybody have idea exactly how? Where are the logical variables, where is CNF?