Maximize Toys Geeksforgeeks

problem

https://practice.geeksforgeeks.org/problems/maximize-toys/0

can anybody tell why it shows runtime error for DP solution.
https://ide.geeksforgeeks.org/ayX4yigrVl

solved using the strategy of 0-1 knapsack.

while solution using heap got AC.
https://ide.geeksforgeeks.org/ptpbOqQRn5

Why do either of those complex things, just sort the array

But anyway, run your code on any maxtest (max constraints) and you’ll get SIGSEGV because your array is too big, you have to make it a global array

1 Like