A9299 | Fox and Card Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Fox Ciel is playing a card game with her friend Fox Jiro. There are $n$ piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
输入格式
The first line contain an integer $n$ ( $1<=n<=100$ ). Each of the next $n$ lines contains a description of the pile: the first integer in the line is $s_{i}$ ( $1<=s_{i}<=100$ ) — the number of cards in the $i$ -th pile; then follow $s_{i}$ positive integers $c_{1}$ , $c_{2}$ , ..., $c_{k}$ , ..., $c_{si}$ ( $1<=c_{k}<=1000$ ) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
输出格式
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
输入输出样例
输入 #1
2 1 100 2 1 10
输出 #1
101 10
输入 #2
1 9 2 8 6 5 9 4 7 1 3
输出 #2
30 15
输入 #3
3 3 1 3 2 3 5 4 6 2 8 7
输出 #3
18 18
输入 #4
3 3 1000 1000 1000 6 1000 1000 1000 1000 1000 1000 5 1000 1000 1000 1000 1000
输出 #4
7000 7000
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted