report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Jealousy - MarisaOJ: Marisa Online Judge

Jealousy

Time limit: 1000 ms
Memory limit: 256 MB
There are $n$ days. On $i^{th}$ day, Marisa can visit Alice Margatroid for $A_i$ happiness, or visit Patchouli Knowledge for $B_i$ happiness. But if she visits one person for 3 or more consecutive days, the other person will get jealous. What is the maximum amount of happiness she can get after $n$ days, without making anyone jealous? ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. - The third line contains $n$ integers $B_i$. ### Output - Print the maximum amount of happiness Marisa can obtain. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i, B_i \le 10^9$. ### Example Input: ``` 4 4 4 4 1 1 1 1 4 ``` Output: ``` 13 ```
Introduction to dynamic programming
Hakurei Shrine
Buying tickets
Reading 2
Longest increasing subsequence
Jealousy
Maximum path 2
Fences painting
Hall
Knapsack 2
Longest common subsequence
Yet another build array problem
Rectangle cutting
Palindrome query
Marisa
Merging elements
Brewing potion 8
Topic
Dynamic Programming
Rating 900
Solution (2) Solution