AT_ndpc2026_n.Knapsack
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are infinitely many items of each of N types. The i-th type of item has weight i and value vi.
You are given Q queries. In each query, you are given a positive integer W.
Find the maximum possible total value when you choose some items such that the total weight is exactly W.
共有 N 种物品,每种物品的数量均为无限。第 i 种物品的重量为 i,价值为 vi。
你将收到 Q 个查询。在每个查询中,你将获得一个正整数 W。
请找出在所选物品总重量恰好为 W 的前提下,所能达到的最大总价值。
输入格式
The input is given from standard input in the following format:
N Q
v1 v2 … vN
query1
query2
⋮
queryQ
Each query is given in the following format:
W
输入从标准输入中按以下格式给出:
N Q
v1 v2 … vN
query1
query2
⋮
queryQ
每个查询按以下格式给出:
W
输出格式
Print Q lines. On the i-th line, output the answer for the i-th query.
输出 Q 行。第 i 行输出第 i 个查询的答案。
输入输出样例
输入#1
4 9 2 1 7 4 1 2 3 4 5 6 7 8 9
输出#1
2 4 7 9 11 14 16 18 21
输入#2
10 10 104 231 361 478 661 765 963 1132 1402 1552 1 10 15 27 48 100 853822501 687675302 281611653 844033520
输出#2
104 1552 2213 4206 7460 15572 133006571782 107124530332 43868837466 131481666104
说明/提示
Note
This problem requires more specialized knowledge compared to the others.
If you do not have an idea for a full solution, it is recommended to aim for partial points and then move on to the next problem.### Partial Score
This problem has partial scoring.
- If you solve the dataset with N≤300, you will get 4 points.
Sample 1 Explanation:
For example, in the 6th query, W=6.
If you take two items of type 3, the total value becomes 7+7=14, which is the maximum.
Constraints
- 1≤N≤4000
- 1≤Q≤2×105
- 0≤vi≤109
- 1≤W≤109
- All input values are integers
注意
本题相较于其他题目需要更专业的知识。
若您尚未想到完整解法,建议先争取部分分,然后继续下一题。
部分分
本题设有部分分。
- 若您解决了满足 N≤300 的数据集,则可获得 4 分。
样例 1 解释:
例如,在第 6 次查询中,W=6。
若选取两个类型为 3 的物品,则总价值为 7+7=14,此为最大值。
限制条件
- 1≤N≤4000
- 1≤Q≤2×105
- 0≤vi≤109
- 1≤W≤109
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?