Dsa
Dynamic Programming
Hard
Maximize Donation Value
A charity organization wants to maximize the total value of donations it can accept over a 1-week period. The organization has a schedule with certain blocks of time when it can accept donations, but the donations are subject to a maximum limit per block. Given an array of integers representing the donation values for each block of time and a maximum limit on the number of blocks that can be selected, calculate the maximum total value of donations that can be accepted.
Input format:
- The first line contains an integer n (1 <= n <= 1000), the number of donation blocks.
- The second line contains n space-separated integers representing the donation values (1 <= value <= 1000).
- The third line contains an integer k (1 <= k <= n), the maximum number of blocks that can be selected.
Output format:
- Print a single integer which is the maximum donation value that can be accepted.
Example:
Input:
5
10 20 30 40 50
3
Output:
90
Key concepts
dynamic_programmingarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now