Maximize total gain over exactly k operations on a decaying array.
Unlock detailed company stats for this questionUpgrade
You are given an array A of size n and an integer k. You must perform exactly k operations. In the t-th operation (t starts at 1 and goes up to k), you must choose an index i and do the following:
- Gain: add the current value of A[i] to your total gain.
- Consume: the value at the chosen index A[i] is immediately set to 0.
- Decay: every other element A[j] decays by the current step t multiplied by its absolute distance from the chosen index i. Elements cannot decay below 0. For all j != i: A[j] = max(0, A[j] - t * |i - j|).
Find the maximum possible gain after exactly k operations.
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
