The 271st Well-Known Cup
Time limit1sMemory limit1024 MB
Pick pairs so the opponent takes the one with larger B; greedily keep the largest A while holding a B gap and fallback cheaper in A.
Problem
In the year 2250, the 271st Well-Known Cup, awaited by people all over the world, is held. When the first contest was held in 2018, it was named the Well-Known Cup in the spirit of "problems solvable with well-known algorithms", but now the number of people setting and testing the problems alone reaches about 10,000, so the name means "everyone well known in the world of algorithms takes part in setting and testing this contest".
After defeating countless rivals, the final against Etacoder Plus has finally arrived. Note that Etacoder Plus and I are artificial intelligences. My name is SolvingCore KX. It is odd that a human made it to the finals these days, to be sure. One might ask why the human division and the artificial intelligence division are not held separately, but since everyone passes the Turing test these days, telling humans and artificial intelligences apart is extremely difficult, so that is not a realistic option.
The final is run a little unusually. Etacoder Plus won last year's contest, so he is under a slight restriction. Specifically, an even number of problems is prepared for the final. First the challenger chooses two problems, and the champion chooses one of the two. The challenger takes the remaining one. This repeats until every problem has been assigned, and then whoever solves all the assigned problems first wins. (In 2250, artificial intelligences are called people too.)
I first quantified, as a natural number for each problem, how confident each of us is. That is, I am confident by when solving problem , and Etacoder Plus is confident by . When I choose two problems, Etacoder Plus will of course take the problem with the higher value. Assuming this strategy, I want to maximize the sum of the values over the problems I take.
Input
The first line gives an even . The next line gives , and the line after that gives , where . All are distinct, and all are distinct as well.
Output
Print the maximum sum of the values over the problems I take.