In The Green Zone CodeChef Solution | CodeChef Problem Solution 2022
There are cans lying on the X-axis at points . Each of the N cans is associated with two values and . Also, the segment between the points and is considered to be green zone including the points and . There are two types of operations -
Select a can out of the cans and move it one unit in either direction along the axis, i.e. if before the operation can is at then after the operation, it moves to either or . This costs coins and it can be performed any number of times for each of the cans.
Choose any integer and shift the green zone to the segment between and , where and are the mirror images of points and with respect to line respectively. This operation should be performed exactly once.
After all the operations, you get number of coins equal to sum of values of of the cans which lie in the final green zone. We define the net coins as:
Find the maximum possible net coins you can earn.
Input Format
- First line will contain , number of testcases. Then the testcases follow.
- Each of the testcases consists of four lines.
- First lines consists of three integers , and .
- Next line consist of space separated integers .
- Next line consist of space separated integers .
- Next line consist of space separated integers .
Output Format
For each testcase, output in a single integer, the maximum number of net coins you can earn.
Constraints
- Sum of over all test cases does not exceed
Sample Input 1
2
1 7 10
2
6
1
3 7 10
2 8 1
6 20 1
1 3 2
Sample Output 1
6
22
Explanation
Test case : Lets choose the axis at and Shift the green zone in the range , such that can lies in green zone. So, there is no need for operation of type and total number of coins earned is , i.e. .
Test case : Choose the axis at , so the new green zone lies in the region . Move the can to . Number of coins received is equal to and number of coins spent is . So, the net coins earned is . This is also the maximum possible.
Join Now for Solution:-
No comments:
Post a Comment