CF725F.Family Photos

普及/提高-

通过率:0%

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 nn 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 aa and bb , indicating that it is worth aa units of happiness to Alice and bb units of happiness to Bonnie. Values of aa and bb 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 xx happiness and Bonnie has yy happiness at the end, you should print xyx-y .

输入格式

The first line of input contains a single integer nn ( 1<=n<=1000001<=n<=100000 ) — the number of two-photo stacks. Then follow nn lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1a_{1} , b1b_{1} , a2a_{2} and b2b_{2} , each not exceeding 10910^{9} . a1a_{1} and b1b_{1} describe the top photo in the stack, while a2a_{2} and b2b_{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
    
首页