#K43577. Maximum Beauty Without Consecutive Stones

    ID: 27340 Type: Default 1000ms 256MiB

Maximum Beauty Without Consecutive Stones

Maximum Beauty Without Consecutive Stones

Sandra has a collection of stones, each with a unique identifier and an associated beauty value. She wishes to choose a subset of these stones such that no two chosen stones have consecutive identifiers. In other words, if two stones have identifiers that differ by exactly $1$, they cannot both be chosen.

Your task is to help Sandra determine the maximum total beauty value she can obtain by selecting a valid subset of stones. Note that it is allowed to pick no stone at all, in which case the result is 0. The input does not guarantee that the stone identifiers are provided in sorted order.

Example

Input:
5
1 2 5 8 9
4 3 6 10 -1

Output: 20

</p>

In the example above, the best solution yields a total beauty of 20.

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains an integer n representing the number of stones.
  • The second line contains n space-separated integers representing the stone identifiers.
  • The third line contains n space-separated integers representing the beauty values corresponding to those stones.

If n = 0, the second and third lines will be empty.

outputFormat

The output should be written to standard output (stdout) and consist of a single integer: the maximum total beauty value obtainable while ensuring that no two selected stones have consecutive identifiers (i.e. differing by exactly $1$).

## sample
5
1 2 5 8 9
4 3 6 10 -1
20