# Whats wrong in my approach (Reduction Game)

Try this testcase:

``````4 5
6 6 7 20
``````

The answer is 35 but I think your code gives 33.

All of the above testcases is working for our solution, but still we got a WA.
Any help would be greatly appreciated.

Solution - REDUCTIONGAME

Try this test case,
2
5 17
20 22 23 24 25
11 5
1 5 6 6 7 8 8 9 9 19 20

Ans.
92
66

This will not work for the case:

1

5 5

9 8 9 8 2

Ans: 26

As you only choose the perform subtraction on elements which are adjacent to each other and the subtraction is done directly to k not stepwise as described in question.

Correct approach:

First sort - 9 9 8 8 2

Reduce - 9 8 7 8 2

Sort - 9 8 8 7 2

Reduce - 9 7 7 7 2

Sort - 9 7 7 7 2

Reduce - 9 6 6 7 2

Sort - 9 7 6 6 2

Reduce - 9 6 5 6 2

Sort - 9 6 6 5 2

Reduce - 9 5 5 5 2

Ans = 26

can anyone who solved this question is willing to share his approach ???

My code is available here

An important testcase:

``````4 2
4 4 4 4

Ans: 10
``````

I have explained my code in comments.

PS: If their are any corrections please suggest them.

@hemant_dhanuka

4 4 4 4

4 3 3 4

3 3 2 4

2 2 2 4

Refer this answer.

then what should be the approach for this problem

or atleast can u please explain how did we got 450 in this test case n=4 k=50 100 100 150 300

@the_extractor its passing yours one as well

can u please explain how did we got 35

6 6 7 20

6 5 6 20

5 5 5 20

Did you get a wrong answer or a TLE?

@the_extractor Wrong Answer

@the_extractor can you please convert this to question i don’t have enough reputation points to convert it to question

I think only you or a mod can convert your answer to a question.

But you can ask a new question instead of converting this.

Initially 100 100 150 300
After 50 operation: 50 100 100 300
Again after 50 operation: 50 50 50 300

Now no two element in array greater than k.
So answer is 450.

@shmabulock : Try this input:

1

5 1

3 9 11 13 25

The answer should be 29 whereas your code gives 25 as the answer.

1 Like