CF358D.Dima and Hares

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.

Dima felt so grateful to Inna about the present that he decided to buy her nn hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to nn from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?

Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and nn don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.

Help Inna maximize the total joy the hares radiate. :)

输入格式

The first line of the input contains integer nn (1<=n<=3000)(1<=n<=3000) — the number of hares. Then three lines follow, each line has nn integers. The first line contains integers a1a_{1} a2a_{2} ...... ana_{n} . The second line contains b1,b2,...,bnb_{1},b_{2},...,b_{n} . The third line contains c1,c2,...,cnc_{1},c_{2},...,c_{n} . The following limits are fulfilled: 0<=ai,bi,ci<=1050<=a_{i},b_{i},c_{i}<=10^{5} .

Number aia_{i} in the first line shows the joy that hare number ii gets if his adjacent hares are both hungry. Number bib_{i} in the second line shows the joy that hare number ii radiates if he has exactly one full adjacent hare. Number сiс_{i} in the third line shows the joy that hare number ii radiates if both his adjacent hares are full.

输出格式

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

输入输出样例

  • 输入#1

    4
    1 2 3 4
    4 3 2 1
    0 1 1 0
    

    输出#1

    13
    
  • 输入#2

    7
    8 5 7 6 1 8 9
    2 7 9 5 4 3 1
    2 3 3 4 1 1 3
    

    输出#2

    44
    
  • 输入#3

    3
    1 1 1
    1 2 1
    1 1 1
    

    输出#3

    4
    
首页