Bullets and Enemies Codechef Solution
There are NN enemies standing from left to right with strengths S1,S2,…,SNS1,S2,…,SN.
MM bullets are to be fired from the left side such that only one bullet is fired at a time. The ithith bullet (1≤i≤M)(1≤i≤M) has power PiPi and capacity CiCi.
This means that the ithith bullet affects the first CiCi alive enemies from the left side and decreases the strength of each of those CiCi enemies by PiPi.
Once an enemy’s strength becomes less than or equal to 00, the enemy dies and its strength becomes 00.
Find the strength of all the enemies after all MM bullets are fired.
Input Format
- First line will contain TT, the number of test cases. Then the test cases follow.
- The first line of each test case contains two space-separated integers NN and MM.
- The second line contains NN space-separated integers S1,S2,…,SNS1,S2,…,SN, denoting strength of the enemies.
- The third line contains MM space-separated integers P1,P2,…,PNP1,P2,…,PN, denoting the power of the ithith bullet.
- The fourth line contains MM space-separated integers C1,C2,…,CNC1,C2,…,CN, denoting the capacity of the ithith bullet.
Output Format
For each test case, output NN space-separated integers denoting the final strength of the enemies.
Constraints
- 1≤T≤1031≤T≤103
- 1≤N,M≤3⋅1051≤N,M≤3⋅105
- 1≤Si,Pi≤1091≤Si,Pi≤109
- 1≤Ci≤N1≤Ci≤N
- Sum of NN over all the test cases does not exceed 3⋅1053⋅105.
- Sum of MM over all the test cases does not exceed 3⋅1053⋅105.
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 11: Initial strength of the enemies is [51,84,24,19,77,10,34][51,84,24,19,77,10,34].
- The power of the first bullet is 33 and the capacity is 22. This means that the first bullet reduces the strength of the first and second enemies by 33. The strength of the enemies after the first bullet is fired: [48,81,24,19,77,10,34][48,81,24,19,77,10,34].
- The power of the second bullet is 66 and the capacity is 22. This means that the second bullet reduces the strength of first and second enemies by 66. The strength of the enemies after the second bullet is fired: [42,75,24,19,77,10,34][42,75,24,19,77,10,34].
- The strength of enemies after third bullet is fired: [39,72,21,16,74,7,34][39,72,21,16,74,7,34].
- The strength of enemies after fourth bullet is fired: [29,62,21,16,74,7,34][29,62,21,16,74,7,34].
Test case 22: Initial strength of the enemies is [10,5,4,8][10,5,4,8].
- The power of the first bullet is 44 and the capacity is 22. This means that the first bullet reduces the strength of the first and second enemies by 44. The strength of the enemies after the first bullet is fired: [6,1,4,8][6,1,4,8].
- The power of the second bullet is 22 and the capacity is 44. This means that the second bullet reduces the strength of the first four enemies by 22. The strength of the enemies after the second bullet is fired: [4,0,2,6][4,0,2,6]. Note that due to this bullet, the second enemy dies and its strength becomes 00.
- The power of the third bullet is 33 and the capacity is 22. This means that the third bullet reduces the strength of the first two alive enemies by 33. The strength of the enemies after the third bullet is fired: [1,0,0,6][1,0,0,6]. Note that since the second enemy is already dead, enemies 11 and 33 are affected by this bullet.
Bullets and Enemies Codechef SOLUTION
Download CodeRead More Post Here