Subset Sum (APCS 2018-10 Advanced Subtask Version)
2.0s 256MChoose any subset of positions from a positive integer sequence, using each position at most once. Find the largest sum not exceeding \(P\). The empty subset is allowed, and equal values at different positions are separate choices.
Input
Read \(n,P\), then \(n\) positive integers.
Constraints
\(1\le n\le25\); \(1\le P,a_i\le1000000009\). This package makes the value bound explicit; values above \(P\) cannot be selected.
Output
Print the maximum sum.
Sample Input
5 17
5 5 8 3 10
Sample Output
16
Source
d007 · 2018-10 APCS. Public subtask version, not the full original.
Log in to write and submit code.
Log in