CF725F.Family Photos

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

爱丽丝和邦妮是姐妹,但她们彼此并不十分喜欢。因此,当阁楼里发现一些老旧的家庭照片时,她们开始争论谁该得到哪些照片。最终,她们决定轮流挑选照片,爱丽丝先选。

共有 nn 堆照片,每堆恰好包含两张照片。在每一轮中,一名玩家只能从某一堆的顶部取走一张照片。

每张照片由两个非负整数 aa 和 bb 描述,表示该照片给爱丽丝带来 aa 单位的幸福感,给邦妮带来 bb 单位的幸福感。不同照片的 aa 和 bb 值可能不同。

允许玩家选择“跳过”(即不取任何照片)。当所有照片均已被取走,或双方连续跳过时,游戏结束。

玩家的目标并非最大化自身的幸福感,而是最大化自身幸福感与妹妹幸福感之差。假设双方均以最优策略进行游戏,请计算爱丽丝的幸福感与邦妮的幸福感之差。即:若存在一场完美博弈,使得最终爱丽丝的幸福感为 xx、邦妮的幸福感为 yy,则输出 x−yx - y。

输入格式

The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — 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 109. _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.

输入的第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)—— 表示双照片堆栈的数量。接下来有 nn 行,每行描述其中一个堆栈。每个堆栈由四个用空格分隔的非负整数 a1a_1、b1b_1、a2a_2 和 b2b_2 描述,且每个数均不超过 10910^9。其中 a1a_1 和 b1b_1 描述堆栈顶部的照片,而 a2a_2 和 b2b_2 描述堆栈底部的照片。

输出格式

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

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

首页