1866. Game

单点时限: 2.0 sec

内存限制: 256 MB

You and your friends have gotten together for a Trivia night at the local pub. Each question is worth a number of points; the i-th element of points corresponds to the score received if you correctly answer the i-th question, but you lose that many points if you answer it incorrectly. The questions are given in the order specified in points, and you must answer each question before the next is asked.

In addition, after each correct answer you will receive a token, and you keep all of your tokens if you answer a question incorrectly. If you then have tokensNeeded tokens, the pub will immediately take all of your tokens and award you additional bonus points. The bonuses are different for each question; element i of bonuses corresponds to the bonus you receive if you win the bonus on question i. Note that it is possible to receive multiple bonuses during the game (see example 0).

You know the answer to all the questions and want to maximize the number of points that you receive. Return the maximum points that you can receive if you correctly choose which questions to answer.

输入格式

There are many test cases!In each test case,the first line is a interger n(1<=n<=1000),stands for there are n questions,then n interger are each question’s worth points in a line.next line is a interger m(1<=m<=1000) stands for tokensNeeded.The last line are n interger of additional bonus points.

-Each element of points will be between 0 and 1000, inclusive.

-bonus will contain the same number of elements as points.

-Each element of bonus will be between 0 and 10000, inclusive.

输出格式

Output the maximum points that you can receive if you correctly choose which questions to answer.

样例

Input
6
1 2 3 4 5 6
3
4 4 4 4 4 4
6
1 2 3 4 5 6
3
1 1 1 20 1 1
Output
29
39
Hint
Case 1:
Answering all six questions correctly will yield the best score in this case, obtaining the bonus after answering the 3rd and 6th questions.
Case 2:
Here, it is better to get the first question wrong so that you get the big bonus on the 4th question.

5 人解决,13 人已尝试。

5 份提交通过,共有 39 份提交。

8.3 EMB 奖励。

创建: 16 年前.

修改: 6 年,7 月前.

最后提交: 10 年,6 月前.

来源: N/A

题目标签