1195C.md (2506B)
1 Source: https://codeforces.com/problemset/problem/1195/C 2 3 C. Basketball Exercise 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in order from left to right. 22 23  24 25 Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all $2n$ students (there are no additional constraints), and a team can consist of any number of students. 26 27 Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose. 28 29 Input 30 31 The first line of the input contains a single integer $n$ ($1 \le n \le 10^5$) — the number of students in each row. 32 33 The second line of the input contains $n$ integers $h_{1, 1}, h_{1, 2}, \ldots, h_{1, n}$ ($1 \le h_{1, i} \le 10^9$), where $h_{1, i}$ is the height of the $i$-th student in the first row. 34 35 The third line of the input contains $n$ integers $h_{2, 1}, h_{2, 2}, \ldots, h_{2, n}$ ($1 \le h_{2, i} \le 10^9$), where $h_{2, i}$ is the height of the $i$-th student in the second row. 36 37 Output 38 39 Print a single integer — the maximum possible total height of players in a team Demid can choose. 40 41 Examples 42 43 Input 44 45 ``` 46 5 47 9 3 5 7 3 48 5 8 1 4 5 49 ``` 50 51 Output 52 53 ``` 54 29 55 ``` 56 57 Input 58 59 ``` 60 3 61 1 2 9 62 10 1 1 63 ``` 64 65 Output 66 67 ``` 68 19 69 ``` 70 71 Input 72 73 ``` 74 1 75 7 76 4 77 ``` 78 79 Output 80 81 ``` 82 7 83 ``` 84 85 Note 86 87 In the first example Demid can choose the following team as follows: 88 89  90 91 In the second example Demid can choose the following team as follows: 92 93 