Training for the World Finals

The UPC team 12 seconds could barely train for the World Finals. For
instance, sometimes only Ferran and Ángel could join for a training. In
those cases, a possible strategy was to make Ferran think about how to
solve the problems, and to make Ángel program the solutions previously
found and written down on paper by Ferran.

Supose that a training had n problems. Let t_(i) be the time that Ferran
needed to solve the i-th problem, and p_(i) be the time that Ángel
needed to program the i-th problem. Both Ferran and Ángel could only
perform one task at a time, but could decide the order of thinking and
the order of programming, with just one restriction: Ferran had to
completely solve a problem before Ángel could start programming its
solution.

Given all this information, can you please minimize the total time to
solve and program all the problems?

Input

Input consists of several cases, each one with n followed by
t₁, …, t_(n), followed by p₁, …, p_(n). Assume 1 ≤ n ≤ 10⁵, and that all
t_(i) and p_(i) are between 1 and 10⁹.

Output

For every case, print the minimum time to solve and program all the
problems.

Problem information

Author: Ferran Alet and Ángel García

Generation: 2026-01-25T11:07:43.553Z

© Jutge.org, 2006–2026.
https://jutge.org
