AT_ndpc2026_n.Knapsack

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are infinitely many items of each of NN types. The ii-th type of item has weight ii and value viv_i.

You are given QQ queries. In each query, you are given a positive integer WW.
Find the maximum possible total value when you choose some items such that the total weight is exactly WW.

共有 NN 种物品,每种物品的数量均为无限。第 ii 种物品的重量为 ii,价值为 viv_i。

你将收到 QQ 个查询。在每个查询中,你将获得一个正整数 WW。
请找出在所选物品总重量恰好为 WW 的前提下,所能达到的最大总价值。

输入格式

The input is given from standard input in the following format:

NN QQ
v1v_1 v2v_2 …\dots vNv_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

WW

输入从标准输入中按以下格式给出:

NN QQ
v1v_1 v2v_2 …\dots vNv_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询按以下格式给出:

WW

输出格式

Print QQ lines. On the ii-th line, output the answer for the ii-th query.

输出 QQ 行。第 ii 行输出第 ii 个查询的答案。

输入输出样例

  • 输入#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≤300N \leq 300, you will get 44 points.

Sample 1 Explanation:
For example, in the 6th query, W=6W=6.
If you take two items of type 33, the total value becomes 7+7=147 + 7 = 14, which is the maximum.

Constraints

  • 1≤N≤40001 \leq N \leq 4000
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 0≤vi≤1090 \leq v_i \leq 10^9
  • 1≤W≤1091 \leq W \leq 10^9
  • All input values are integers

注意

本题相较于其他题目需要更专业的知识。
若您尚未想到完整解法,建议先争取部分分,然后继续下一题。

部分分

本题设有部分分。

  • 若您解决了满足 N≤300N \leq 300 的数据集,则可获得 44 分。

样例 1 解释:
例如,在第 6 次查询中,W=6W=6。
若选取两个类型为 33 的物品,则总价值为 7+7=147 + 7 = 14,此为最大值。

限制条件

  • 1≤N≤40001 \leq N \leq 4000
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 0≤vi≤1090 \leq v_i \leq 10^9
  • 1≤W≤1091 \leq W \leq 10^9
  • 所有输入值均为整数

输入解题思路,AI测评打分。不知道怎么写?

首页