#P2029. 跳舞

跳舞

Description

Xiao Ming got a dance pad game program called Dance. In each round, the game outputs NN moving "arrows", numbered 11 to NN, and the corresponding scores are S1,S2,,SNS_1, S_2, \ldots, S_N. If you hit arrow ii, you gain SiS_i points; otherwise, you lose SiS_i points.

Additionally, the game has an accumulation reward: if the accumulated number of hits reaches TT upon hitting arrow ii, you receive a bonus of BiB_i points, and the accumulated count is reset to 00 and restarted.

For example: N=6,T=3N = 6, T = 3, and the sequences SS and BB are {1, 2, 3, 4, 5, 6} and {0, 0, 4, 7, 9, 10}, respectively. If Xiao Ming hits all arrows, the score is: (1+2+3+4)+(4+5+6+10)=35(1+2+3+4) + (4+5+6+10) = 35.

Xiao Ming is a Dance expert and can hit any arrows he chooses. However, he finds that for given N,T,S,BN, T, S, B, 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 NN and TT.

The second line contains NN integers, the scores of SS.

The third line contains NN integers, the bonuses of BB.

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, 0N,T1000 \le N, T \le 100.
  • For 100% of the testdata, 0N,T50000 \le N, T \le 5000.
  • The sequences SS and BB each contain NN numbers, and all scores are integers in [0,10000][0, 10000].

Translated by ChatGPT 5