Under construction

Still being built. Things may change

DDR Stamina Management

Interview

Time limit1sMemory limit1024 MB

Summary
Choose which sections to play so total points are maximized, where stamina recovers by K before each section (capped at 100) and playing costs h_i stamina.
Level

Medium4 of 10

Topics
Dynamic programming, Implementation
Solved
No attempts yet

Problem

Coderbak, a rhythm gamer, has recently been hooked on Dance Dance Revolution (DDR). In this game, the player steps on pads in time with notes that fall while the song plays. The game drains a lot of stamina, so managing stamina matters a great deal.

The song has NN sections. For each section ii (1≤i≤N)(1 \leq i \leq N), Coderbak can choose to play it or skip it. Playing section ii earns sis_i points and costs hih_i stamina. Skipping a section earns no points and costs no stamina.

When the song starts, Coderbak has 100100 stamina. Before entering each section, his stamina recovers by KK. This recovery happens whether he plays or skips the section. If the stamina after recovery exceeds 100100, it becomes 100100. If playing a section would drop his stamina below 00, Coderbak must skip that section.

After a full day of DDR, Coderbak is exhausted and can no longer make decisions about managing his stamina. Write a program that outputs the maximum score he can earn so that he can still perform well.

Game over and other systems not mentioned in this statement are not considered in this problem.

Input

The first line contains two integers NN and KK, separated by a space. NN is the total number of sections in the song, and KK is the amount of stamina recovered. (1≤N≤1000;1≤K≤10)(1 \leq N \leq 1000; 1 \leq K \leq 10)

The second line contains integers s1,s2,⋯ ,sNs_1, s_2, \cdots, s_N, separated by spaces. (1≤si≤1000)(1 \leq s_i \leq 1000)

The third line contains integers h1,h2,⋯ ,hNh_1, h_2, \cdots, h_N, separated by spaces. (1≤hi≤100)(1 \leq h_i \leq 100)

Output

Print the maximum score Coderbak can earn.

Examples2

  1. Example 1

    Input
    10 10
    1 2 3 4 5 6 7 8 9 10
    9 9 9 9 9 9 9 9 9 9
    
    Expected output
    55
    
  2. Example 2

    Input
    5 10
    70 90 80 100 60
    60 60 60 60 60
    
    Expected output
    190