No.3670 Fast Knapsack
問題文最終更新日: 2026-09-03 16:29:09
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 512 BONSAI
(順位表)
の他の問題:
Problem Statement
You are given a sequence of positive integers $A=(A_1,A_2,\ldots,A_N)$ of length $N$ and a positive integer $S$.
Among the subsets $U$ of $\{1,2,\ldots,N\}$ satisfying $\sum_{i\in U}A_i\leq S$, find the maximum value of $\sum_{i\in U}A_i$.
Solve $T$ test cases.
Input
The input is given from Standard Input in the following format.
$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$
$\text{case}_i$ is given in the following format.
$N\ S$ $A_1\ A_2\ \ldots\ A_N$
- $1\leq T\leq 10^5$
- $1\leq N\leq 10^5$
- $1\leq S, A_i\leq 2\times 10^5$
- All input values are integers.
- The sum of $N$ in a single input file does not exceed $10^5$.
Output
For each test case, print the answer on $1$ line. Print a newline at the end.
Sample
Sample 1
Input
5 5 11 2 4 5 7 9 3 4 5 6 7 4 20 2 3 4 5 5 100000 99999 99998 50001 50000 49999 3 10 6 5 5
Output
11 0 14 100000 10
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
harurun