Array cost@test case failed

https://ide.codingblocks.com/s/52795
https://hack.codingblocks.com/contests/c/512/270

my ans is coming correct but failed 1 test case

Check constraints, n^2 approach will not work.
think something else.

but if the logic is correct then whats the problem , atleast it should give the correct output

It is giving correct answer but only for small value of n
in case of large n your code will fail.

1 Like

plz suggest something

Hint: Use mergeSort kind of approach. divide and conquer.

Give a try using this approach, if still, you face problem do post it.

Hit Like if you get it.
Happy_coding!

1 Like