#P2029. 跳舞
跳舞
Description
Xiao Ming got a dance pad game program called Dance. In each round, the game outputs moving "arrows", numbered to , and the corresponding scores are . If you hit arrow , you gain points; otherwise, you lose points.
Additionally, the game has an accumulation reward: if the accumulated number of hits reaches upon hitting arrow , you receive a bonus of points, and the accumulated count is reset to and restarted.
For example: , and the sequences and are {1, 2, 3, 4, 5, 6} and {0, 0, 4, 7, 9, 10}, respectively. If Xiao Ming hits all arrows, the score is: .
Xiao Ming is a Dance expert and can hit any arrows he chooses. However, he finds that for given , hitting all arrows does not necessarily yield the highest score. He wants to know the maximum possible score. Can you help him compute the maximum obtainable total score?
Input Format
The first line contains two integers and .
The second line contains integers, the scores of .
The third line contains integers, the bonuses of .
Output Format
Output one integer, the maximum obtainable score.
6 3
1 2 3 4 5 6
1 1 1 20 1 1
39
Hint
Sample explanation:
Skip the first arrow and lose 1 point, then hit 3 arrows to gain 9 points and receive an additional 20 points in bonus, then hit 2 more arrows, for a total of 39 points.
Constraints:
- For 20% of the testdata, .
- For 100% of the testdata, .
- The sequences and each contain numbers, and all scores are integers in .
Translated by ChatGPT 5
京公网安备 11011102002149号