No.2999 Long Long Friedrice
Story
friedrice-kun is far too short, so he went to a pharmacy to buy a potion that makes him taller.
There, the pharmacy was selling a medicine called "Seganobiiru".
Problem Statement
friedrice-kun's height is initially $1$ cm.
He has $N$ bottles of Seganobiiru.
If the user's height is $A_i$ cm when drinking the $i$-th bottle of Seganobiiru, their height increases by $B_i$ cm.
Otherwise, nothing happens when drinking that bottle of Seganobiiru.
Given that he may drink the $N$ bottles of Seganobiiru in any order, what is the maximum possible height, in cm, of friedrice-kun after drinking all $N$ bottles?
Input
$N$ $A_1\ A_2\ \dots\ A_N$ $B_1\ B_2\ \dots\ B_N$
Output
Output the maximum possible height of friedrice-kun after drinking all $N$ bottles.
Sample
Sample 1
Input
2 1 4 3 2
Output
6
Since friedrice-kun's height is initially $1$ cm, he drinks the $1$-st bottle of Seganobiiru.
Then his height increases by $3$ cm and becomes $4$ cm.
After that, when he drinks the $2$-nd bottle of Seganobiiru, his height increases by $2$ cm and becomes $6$ cm.
His height cannot be made greater than $6$ cm, so output 6.
Sample 2
Input
1 10 5
Output
1
Drinking the Seganobiiru does not change friedrice-kun's height, so output 1.
Sample 3
Input
5 1 1 3 4 7 2 3 4 2 5
Output
12
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。