Bullets and Enemies

 There are 

enemies standing from left to right with strengths

.

bullets are to be fired from the left side such that only one bullet is fired at a time. The bullet has power and capacity .
This means that the bullet affects the first alive enemies from the left side and decreases the strength of each of those enemies by

.

Once an enemy’s strength becomes less than or equal to

, the enemy dies and its strength becomes

.

Find the strength of all the enemies after all

bullets are fired.

Input Format

  • First line will contain
  • , the number of test cases. Then the test cases follow.
  • The first line of each test case contains two space-separated integers
  • and
  • .
  • The second line contains
  • space-separated integers
  • , denoting strength of the enemies.
  • The third line contains
  • space-separated integers , denoting the power of the
  • bullet.
  • The fourth line contains
  • space-separated integers , denoting the capacity of the
    • bullet.

    Output Format

    For each test case, output

    space-separated integers denoting the final strength of the enemies.

    Constraints

  • Sum of
  • over all the test cases does not exceed
  • .
  • Sum of
  • over all the test cases does not exceed
    • .

    Sample Input 1

    2
    7 4
    51 84 24 19 77 10 34
    3 6 3 10
    2 2 6 2
    4 3
    10 5 4 8
    4 2 3
    2 4 2
    

    Sample Output 1

    29 62 21 16 74 7 34
    1 0 0 6
    

    Explanation

    Test case

    : Initial strength of the enemies is

    .

    • The power of the first bullet is
    and the capacity is . This means that the first bullet reduces the strength of the first and second enemies by . The strength of the enemies after the first bullet is fired:
  • .
  • The power of the second bullet is
  • and the capacity is . This means that the second bullet reduces the strength of first and second enemies by . The strength of the enemies after the second bullet is fired:
  • .
  • The strength of enemies after third bullet is fired:
  • .
  • The strength of enemies after fourth bullet is fired:
    • .

    Test case

    : Initial strength of the enemies is

    .

    • The power of the first bullet is
    and the capacity is . This means that the first bullet reduces the strength of the first and second enemies by . The strength of the enemies after the first bullet is fired:
  • .
  • The power of the second bullet is
  • and the capacity is . This means that the second bullet reduces the strength of the first four enemies by . The strength of the enemies after the second bullet is fired: . Note that due to this bullet, the second enemy dies and its strength becomes
  • .
  • The power of the third bullet is
  • and the capacity is . This means that the third bullet reduces the strength of the first two alive enemies by . The strength of the enemies after the third bullet is fired: . Note that since the second enemy is already dead, enemies and are affected by this bullet.
    Previous
    Next Post »