Negative Asset Pickup
Preview mode. Log in to edit, run, submit, and save progress.
Negative Asset Pickup
A liquidation desk lists devices with signed disposal values. A negative value means the owner pays the desk to take that device; a positive value means the desk would have to pay. The truck can collect at most m devices. For each list, report the maximum money the desk can earn from collected devices. Input Format: The first line contains t, the number of test cases. Each test case contains n and m, followed by n signed values. Output Format: For each test case, print the maximum earnable amount.
Examples
1 5 3 -6 0 35 -2 4
8
Explanation: The desk can collect the devices with values -6 and -2, earning 6 + 2 = 8. Taking zero or positive values would not increase the money earned.
Approach hint
Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.