#C869. Total Time to Solve Problems

    ID: 52699 Type: Default 1000ms 256MiB

Total Time to Solve Problems

Total Time to Solve Problems

Nina has a set of programming problems where each problem has an associated difficulty level and a required time to solve. When Nina approaches her contest, she decides to solve the problems in increasing order of their difficulty. Given the number of problems and two lists (one for the difficulties and one for the times required), your task is to calculate and output the total time she will take to solve all the problems following the increasing order of difficulty.

Mathematically, if the difficulties and times are given as (d_1, d_2, \ldots, d_n) and (t_1, t_2, \ldots, t_n) respectively, then after sorting the problems by (d_i) (in ascending order), the answer is (\sum_{i=1}^{n} t_i). Note that even though addition is commutative, the sorting step is essential as it represents the intended problem-solving order.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (n) representing the number of problems. The second line contains (n) space-separated integers representing the difficulties of the problems. The third line contains (n) space-separated integers representing the times required to solve each problem.

outputFormat

Output a single integer via standard output (stdout), which is the total time required to solve all the problems when solved in increasing order of difficulty.## sample

4
4 2 1 3
5 3 4 2
14