CF1912A.Accumulator Apex

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Allyn is playing a new strategy game called "Accumulator Apex". In this game, Allyn is given the initial value of an integer xx, referred to as the accumulator, and kk lists of integers. Allyn can make multiple turns. On each turn, Allyn can withdraw the leftmost element from any non-empty list and add it to the accumulator xx if the resulting xx is non-negative. Allyn can end the game at any moment. The goal of the game is to get the largest possible value of the accumulator xx. Please help Allyn find the largest possible value of the accumulator xx they can get in this game.

阿林正在玩一款名为“累加器巅峰”的新策略游戏。在该游戏中,阿林会获得一个整数 xx 的初始值(称为累加器)以及 kk 个整数列表。阿林可以进行多轮操作。在每一轮中,阿林可以从任意一个非空列表中取出其最左侧的元素,并将其加到累加器 xx 上——但前提是相加后得到的 xx 为非负数。阿林可在任意时刻结束游戏。本游戏的目标是使累加器 xx 的值尽可能大。请帮助阿林找出该游戏所能达到的最大可能的累加器 xx 值。

输入格式

The first line of the input contains two integers xx and kk (0≤x≤109,1≤k≤1050 \leq x \leq 10^9, 1 \leq k \leq 10^5) — the initial value of the accumulator xx and the number of lists. The next kk lines contain the description of lists: an integer lil_i (li≥1l_i \ge 1) followed on the same line by lil_i elements of the list in the order from left to right. Each element of lists does not exceed 10910^9 by the absolute value, and the total size of all lists does not exceed 10510^5.

输入的第一行包含两个整数 xx 和 kk(0≤x≤1090 \leq x \leq 10^9,1≤k≤1051 \leq k \leq 10^5)—— 分别表示累加器的初始值 xx 和列表的个数。接下来的 kk 行描述各个列表:每行首先是一个整数 lil_i(li≥1l_i \ge 1),随后在同一行中给出该列表的 lil_i 个元素,顺序为从左到右。每个列表元素的绝对值不超过 10910^9,且所有列表的总长度不超过 10510^5。

输出格式

The sole line of the output should contain the largest value of the accumulator xx Allyn can get.

输出的唯一一行应包含阿林能够得到的累加器 xx 的最大值。

输入输出样例

  • 输入#1

    1 3
    2 -1 2
    2 -2 3
    2 -3 4

    输出#1

    4
  • 输入#2

    1 2
    3 -1 -1 4
    4 1 -3 -4 8

    输出#2

    4

说明/提示

In the first input, we start with x=1x = 1. Then, we can take the first integer from the first list and get x=0x = 0 — adding the next integer 22 from the first list we get x=2x = 2. After that, we can add the integers from the second list and obtain x=3x = 3. Finally, we can add the integers from the third list and obtain x=4x = 4.

In the second input, we can add the first integer from the second list and get x=2x = 2. Then, by adding the elements from the first list, we get x=4x = 4. We cannot add more integers to increase xx.

在第一个输入中,我们从 x=1x = 1 开始。接着,我们可以取第一个列表中的第一个整数,得到 x=0x = 0;再将第一个列表中的下一个整数 22 加上,得到 x=2x = 2。之后,我们可以加上第二个列表中的整数,得到 x=3x = 3。最后,我们可以加上第三个列表中的整数,得到 x=4x = 4。

在第二个输入中,我们可以加上第二个列表中的第一个整数,得到 x=2x = 2。然后,通过加上第一个列表中的元素,得到 x=4x = 4。我们无法再添加更多整数来增大 xx。

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

首页