A8444 | Porcelain
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed.
The collection of porcelain is arranged neatly on $n$ shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items — the leftmost or the rightmost item, not the ones in the middle of the shelf. Once an item is taken, the next item on that side of the shelf can be accessed (see example). Once an item is taken, it can't be returned to the shelves.
You are given the values of all items. Your task is to find the maximal damage the princess' tantrum of $m$ shrieks can inflict on the collection of porcelain.
The collection of porcelain is arranged neatly on $n$ shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items — the leftmost or the rightmost item, not the ones in the middle of the shelf. Once an item is taken, the next item on that side of the shelf can be accessed (see example). Once an item is taken, it can't be returned to the shelves.
You are given the values of all items. Your task is to find the maximal damage the princess' tantrum of $m$ shrieks can inflict on the collection of porcelain.
输入格式
The first line of input data contains two integers $n$ ( $1<=n<=100$ ) and $m$ ( $1<=m<=10000$ ). The next $n$ lines contain the values of the items on the shelves: the first number gives the number of items on this shelf (an integer between $1$ and $100$ , inclusive), followed by the values of the items (integers between $1$ and $100$ , inclusive), in the order in which they appear on the shelf (the first number corresponds to the leftmost item, the last one — to the rightmost one). The total number of items is guaranteed to be at least $m$ .
输出格式
Output the maximal total value of a tantrum of $m$ shrieks.
输入输出样例
输入 #1
2 3 3 3 7 2 3 4 1 5
输出 #1
15
输入 #2
1 3 4 4 3 1 2
输出 #2
9
In the first case there are two shelves, each with three items. To maximize the total value of the items chosen, one can take two items from the left side of the first shelf and one item from the right side of the second shelf.
In the second case there is only one shelf, so all three items are taken from it — two from the left side and one from the right side.
In the second case there is only one shelf, so all three items are taken from it — two from the left side and one from the right side.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted