# Choose \$n\$ out of \$2n-1\$ boxes containing at least half of all white balls and half of all black balls

We are given $$2n – 1$$ boxes with black and white balls. In the $$i$$-th, box there are $$w_i$$ white and $$b_i$$ black balls. It is required to choose $$n$$ boxes so that, the sum of the white balls is at least $$W/2$$, and the sum of black balls is at least $$B/2$$. Solve for $$O(n\log{n})$$.

What I am currently thinking is this:

Generate some hashtable to be able to track the boxes that we chose.
Sort the boxes by the quantity of the white (in increasing order) balls and chose the last $$n$$ balls every time keeping them in our hashtable.
Sort by the quantity of the black balls and do the same. Check every time to see if we already chose the box or not. Here comes the problem: Suppose we didn’t. Then we can face a situation where we already have $$n$$ boxes that have in total at least $$W/2$$ white balls but at the same time, they have in total less than $$B/2$$ black balls. How can we overcome this problem?

We can’t just switch the chosen boxes that have the least number of white balls with the one that have the maximum available number of black balls since the box with white balls can contain significant amount of black balls on its own.

Posted on Categories proxies
{"ft_lang_label":"__label__en","ft_lang_prob":0.91388464,"math_prob":0.9986638,"size":1153,"snap":"2020-45-2020-50","text_gpt3_token_len":284,"char_repetition_ratio":0.16623151,"word_repetition_ratio":0.017391304,"special_character_ratio":0.2584562,"punctuation_ratio":0.073469386,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9975244,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-28T19:19:42Z\",\"WARC-Record-ID\":\"<urn:uuid:eb86feb8-7f65-41db-95d8-d42340e353d7>\",\"Content-Length\":\"25003\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a061cb7f-6da4-4dbf-8e0d-a85127aa8416>\",\"WARC-Concurrent-To\":\"<urn:uuid:8505a8c1-ebcd-431b-872c-96d9ffa88d53>\",\"WARC-IP-Address\":\"173.212.203.156\",\"WARC-Target-URI\":\"https://proxieslive.com/choose-n-out-of-2n-1-boxes-containing-at-least-half-of-all-white-balls-and-half-of-all-black-balls/\",\"WARC-Payload-Digest\":\"sha1:JHOQ6ZQA2Y3LYSSWDEUWZQZVOTI5GL4B\",\"WARC-Block-Digest\":\"sha1:GKVZFPGOU6FHPLBHHGYXIVMUR74XTRGT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141195745.90_warc_CC-MAIN-20201128184858-20201128214858-00310.warc.gz\"}"}