A10614 | Family Photos
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.
There are $n$ stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.
Each photo is described by two non-negative integers $a$ and $b$ , indicating that it is worth $a$ units of happiness to Alice and $b$ units of happiness to Bonnie. Values of $a$ and $b$ might differ for different photos.
It's allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.
The players don't act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister's. Assuming both players play optimal, find the difference between Alice's and Bonnie's happiness. That is, if there's a perfectly-played game such that Alice has $x$ happiness and Bonnie has $y$ happiness at the end, you should print $x-y$ .
There are $n$ stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.
Each photo is described by two non-negative integers $a$ and $b$ , indicating that it is worth $a$ units of happiness to Alice and $b$ units of happiness to Bonnie. Values of $a$ and $b$ might differ for different photos.
It's allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.
The players don't act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister's. Assuming both players play optimal, find the difference between Alice's and Bonnie's happiness. That is, if there's a perfectly-played game such that Alice has $x$ happiness and Bonnie has $y$ happiness at the end, you should print $x-y$ .
输入格式
The first line of input contains a single integer $n$ ( $1<=n<=100000$ ) — the number of two-photo stacks. Then follow $n$ lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers $a_{1}$ , $b_{1}$ , $a_{2}$ and $b_{2}$ , each not exceeding $10^{9}$ . $a_{1}$ and $b_{1}$ describe the top photo in the stack, while $a_{2}$ and $b_{2}$ describe the bottom photo in the stack.
输出格式
Output a single integer: the difference between Alice's and Bonnie's happiness if both play optimally.
输入输出样例
输入 #1
2 12 3 4 7 1 15 9 1
输出 #1
1
输入 #2
2 5 4 8 8 4 12 14 0
输出 #2
4
输入 #3
1 0 10 0 10
输出 #3
-10
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted