Geekflix
시간 제한3초메모리 제한1024 MB
원형으로 배치된 n개 스트림에서 i번째를 k번째 재생하면 max(a_i-(k-1)b_i, 0) 코인을 받는다. 버튼을 m번 눌러 얻는 최대 코인을 구한다.
문제
George got COVID-19 in this morning. He must stay at home in the next seven days for quarantine. As a geek, George only watches Geekflix, the video streaming service for geeks, for recreation during his quarantine period. Geekflix provides video streams numbered from to , and Geekflix also gives some geeky coins to the audiences in their quarantine periods. When George watches stream for the -th time in his quarantine period, George gets geeky coins.
The Geekflix app arranges the video streams on a circle. For , the previous stream of stream is stream . The previous stream of stream is stream . For , the next stream of stream is stream . The next stream of stream is stream . When George opens the Geekflix app on his TV, the Geekflix app points the cursor at stream .
The remote controller has three buttons: previous, next, and play. When George presses the previous button, the Geekflix app points the cursor to the previous stream. When George presses the next button, the Geekflix app points the cursor to the next stream. When George presses the play button, the Geekflix app plays the stream pointed by the cursor. The cursor points to the same stream after playing.
George may press the buttons times during his quarantine period, and he wants to get as many geeky coins as possible. What is the maximum number of geeky coins that George can get during his quarantine period?
입력
The first line contains two positive integers and . is the number of video streams, and George may press the buttons times. The second line contains positive integers , and the third line contains non-negative integers . These integers define the number of geeky coins awarded to George when the Geekflix app plays video streams.
출력
Output the maximum number of geeky coins that George can get during his quarantine period.
제한
- for .