408154: GYM103029 A John and nuts

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. John and nutstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

John decided to eat nuts. He has $$$x$$$ nuts in a box. There are $$$n$$$ types of nuts in the box. The box contains $$$a_i$$$ nuts of i-th type.

John wants to eat only one nut, but this nut must be one of the $$$k$$$ defined types – $$$b_1, b_2, \ldots b_k$$$.

John starts taking nuts out of the box blindly. What's the minimum amount of nuts that John must take to guarantee in this 'taken' nuts, John will find the type, that he would like to eat?

Input

The first line contains two integers $$$n, x$$$: $$$(1 \le n \le 10^5, 1 \le x \le 10^7)$$$.

The second line contains an array $$$a$$$ with $$$n$$$ integers: ($$$1 \le a_i \le x$$$). Note that $$$a_1 + a_2 + \ldots + a_n = x$$$.

The third line contains one integer $$$1 \le k \le n$$$.

The fourth line contains an array $$$b$$$ with $$$k$$$ different integers: $$$1 \le b_i \le n$$$, where $$$b_i$$$ – $$$i$$$-th type of nuts that John wants to eat.

Output

Output a single number $$$answer$$$ – how many nuts John needs to take at least to guarantee that he will take the type of nut he wants to eat.

ExampleInput
5 19
9 1 2 3 4
2
2 4
Output
16
Note

In the first test, John cannot draw $$$15$$$ nuts, as it may happen that he will draw $$$9$$$ nuts of type $$$1$$$, $$$2$$$ nuts of type $$$3$$$, and $$$4$$$ nuts of type $$$5$$$. It can be shown that $$$16$$$ nuts will always be enough.

加入题单

上一题 下一题 算法标签: