Cute Panda
Time limit2sMemory limit512 MB
Each panda splits its donuts between bin i and bin i+1 (cyclically); find the maximum total donuts the bins can absorb.
- Level
Medium7 of 10
- Topics
- Greedy, Array, Implementation, Math
- Solved
- No attempts yet
Problem
There are pandas numbered from to , and the -th panda has donuts. There are also bins numbered from to , and the -th bin can hold up to donuts. For every from to , the -th panda can distribute his donuts between the -th bin and the -th bin.
Find the maximum number of donuts that can be distributed.
Input
The input contains zero or more test cases, and is terminated by end-of-file. Each test case is given as follows.
The first line contains an integer ().
The second line contains integers ().
The third line contains integers ().
The sum of all over all test cases does not exceed .
Output
For each test case, output one integer: the maximum number of donuts that can be distributed.