click below for solution

Monday, 31 January 2022

Make Them Equal solution|educational Codeforces round 122 (rated for div 2)

D. Make Them Equal
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array of integers a of size n. Initially, all elements of the array are equal to 1. You can perform the following operation: choose two integers i (1in) and x (x>0), and then increase the value of ai by aix (i.e. make ai=ai+aix).

After performing all operations, you will receive ci coins for all such i that ai=bi.

Your task is to determine the maximum number of coins that you can receive by performing no more than k operations.

Input

The first line contains a single integer t (1t100) — the number of test cases.

The first line of each test case contains two integers n and k (1n103;0k106) — the size of the array and the maximum number of operations, respectively.

The second line contains n integers b1,b2,,bn (1bi103).

The third line contains n integers c1,c2,,cn (1ci106).

The sum of n over all test cases does not exceed 103.

Output

For each test case, print one integer — the maximum number of coins that you can get by performing no more than k operations.

Solution: 

solution link 1

https://shareus.in/?i=GZatxNl0g


if 1st link is not work then click on another link

Solution link 2

https://shrinke.me/0joa


Solution link 3

https://afly.pro/4dPM5oi


Solution link 4

https://afly.pro/X6gV2u4


How to get link tutorial video link

https://youtu.be/0TSsPHhgwb4


No comments:

Post a Comment