AT_ndpc2026_o.Game

入门

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are going to play a game. The game consists of actions over NN days. Each day, you choose an integer x∈0,1,2x \in {0,1,2}, pay xx yen, and perform action xx. If you perform action xx on day ii, you gain Ai,xA_{i,x} experience points. You cannot perform more than one action per day.

You are given QQ queries. In each query, you are given a pair of integers (d,b)(d, b) such that 1≤d≤N1 \leq d \leq N and 0≤b≤2d0 \leq b \leq 2d. Solve the following problem:

  • Suppose you spend exactly bb yen in total from day 11 to day dd. What is the maximum possible total experience you can gain during these dd days?

You are given TT test cases. Solve each of them.

你将进行一场游戏。游戏持续 NN 天,每天你需要执行一个操作。每天,你需选择一个整数 x∈{0,1,2}x \in \{0,1,2\},支付 xx 日元,并执行操作 xx。若在第 ii 天执行操作 xx,你将获得 Ai,xA_{i,x} 点经验值。每天至多只能执行一个操作。

你将收到 QQ 个查询。每个查询给出一对整数 (d,b)(d, b),满足 1≤d≤N1 \leq d \leq N 且 0≤b≤2d0 \leq b \leq 2d。请解决如下问题:

  • 假设你在第 11 天至第 dd 天期间恰好总共花费 bb 日元,那么这 dd 天内你能获得的最大总经验值是多少?

你将收到 TT 组测试数据,请对每组数据求解。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN QQ
A1,0A_{1,0} A1,1A_{1,1} A1,2A_{1,2}
A2,0A_{2,0} A2,1A_{2,1} A2,2A_{2,2}
⋮\vdots
AN,0A_{N,0} AN,1A_{N,1} AN,2A_{N,2}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

dd bb

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN QQ
A1,0A_{1,0} A1,1A_{1,1} A1,2A_{1,2}
A2,0A_{2,0} A2,1A_{2,1} A2,2A_{2,2}
⋮\vdots
AN,0A_{N,0} AN,1A_{N,1} AN,2A_{N,2}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

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

dd bb

输出格式

Output the answers for all test cases in order.
For each test case, print QQ lines. On the ii-th line, output the answer to the ii-th query.

按顺序输出所有测试用例的答案。
对于每个测试用例,输出 QQ 行。在第 ii 行输出第 ii 个查询的答案。

输入输出样例

  • 输入#1

    2
    3 3
    1 3 2
    4 8 1
    1 6 9
    1 1
    2 3
    3 3
    5 5
    45 58 82
    47 39 94
    36 54 74
    80 61 95
    61 57 69
    2 4
    5 7
    4 1
    5 5
    3 0

    输出#1

    3
    10
    18
    176
    387
    226
    371
    128
  • 输入#2

    1
    10 10
    76 30 16
    30 94 48
    60 67 90
    43 63 47
    49 33 66
    14 49 79
    39 62 37
    34 79 96
    29 86 85
    59 42 69
    10 16
    10 13
    10 8
    10 20
    10 2
    10 5
    10 4
    10 0
    10 15
    10 19

    输出#2

    764
    770
    724
    633
    554
    664
    634
    433
    780
    679

说明/提示

Partial Score

This problem has partial scoring.

  • If all queries satisfy d=Nd = N, you will get 55 points.

Sample 1 Explanation:
For example, consider the 33-rd query of the first test case: d=3,b=3d=3, b=3.
You can achieve a total experience of 1818 in the following way, which is optimal:

  • Day 11: choose x=0x=0. Pay 00 yen and gain A1,0=1A_{1,0}=1 experience.
  • Day 22: choose x=1x=1. Pay 11 yen and gain A2,1=8A_{2,1}=8 experience.
  • Day 33: choose x=2x=2. Pay 22 yen and gain A3,2=9A_{3,2}=9 experience.

Constraints

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤2.5×1051 \leq N \leq 2.5 \times 10^5
  • 1≤Q≤1041 \leq Q \leq 10^4
  • 0≤Ai,x≤1090 \leq A_{i,x} \leq 10^9
  • 1≤d≤N1 \leq d \leq N
  • 0≤b≤2d0 \leq b \leq 2d
  • The sum of NN over all test cases is at most 2.5×1052.5 \times 10^5
  • The sum of QQ over all test cases is at most 10410^4
  • All input values are integers

部分得分

本题采用部分得分制。

  • 若所有查询均满足 d=Nd = N,则可获得 55 分。

样例 1 解释:
例如,考虑第一个测试用例的第 33 个查询:d=3, b=3d=3,\ b=3。
以下方式可获得总计 1818 点经验,且该方案为最优:

  • 第 11 天:选择 x=0x=0。花费 00 日元,获得 A1,0=1A_{1,0}=1 点经验。
  • 第 22 天:选择 x=1x=1。花费 11 日元,获得 A2,1=8A_{2,1}=8 点经验。
  • 第 33 天:选择 x=2x=2。花费 22 日元,获得 A3,2=9A_{3,2}=9 点经验。

限制条件

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤2.5×1051 \leq N \leq 2.5 \times 10^5
  • 1≤Q≤1041 \leq Q \leq 10^4
  • 0≤Ai,x≤1090 \leq A_{i,x} \leq 10^9
  • 1≤d≤N1 \leq d \leq N
  • 0≤b≤2d0 \leq b \leq 2d
  • 所有测试用例的 NN 之和不超过 2.5×1052.5 \times 10^5
  • 所有测试用例的 QQ 之和不超过 10410^4
  • 所有输入值均为整数

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

首页