CF1792B.Stand-up Comedian

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Eve is a beginner stand-up comedian. Her first show gathered a grand total of two spectators: Alice and Bob.

Eve prepared a1+a2+a3+a4a_1 + a_2 + a_3 + a_4 jokes to tell, grouped by their type:

  • type 1: both Alice and Bob like them;
  • type 2: Alice likes them, but Bob doesn't;
  • type 3: Bob likes them, but Alice doesn't;
  • type 4: neither Alice nor Bob likes them.

Initially, both spectators have their mood equal to 00 . When a spectator hears a joke he/she likes, his/her mood increases by 11 . When a spectator hears a joke he/she doesn't like, his/her mood decreases by 11 . If the mood of a spectator becomes negative (strictly below zero), he/she leaves.

When someone leaves, Eve gets sad and ends the show. If no one leaves, and Eve is out of jokes, she also ends the show.

Thus, Eve wants to arrange her jokes in such a way that the show lasts as long as possible. Help her to calculate the maximum number of jokes she can tell before the show ends.

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of testcases.

The only line of each testcase contains four integers a1,a2,a3,a4a_1, a_2, a_3, a_4 ( 0a1,a2,a3,a41080 \le a_1, a_2, a_3, a_4 \le 10^8 ; a1+a2+a3+a41a_1 + a_2 + a_3 + a_4 \ge 1 ) — the number of jokes of each type Eve prepared.

输出格式

For each testcase, print a single integer — the maximum number of jokes Eve can tell before at least one of the spectators leaves or before she runs out of jokes.

输入输出样例

  • 输入#1

    4
    5 0 0 0
    0 0 0 5
    2 5 10 6
    3 0 0 7

    输出#1

    5
    1
    15
    7

说明/提示

In the first testcase, Eve only has jokes of the first type. Thus, there's no order to choose. She tells all her jokes, both Alice and Bob like them. Their mood becomes 55 . The show ends after Eve runs out of jokes.

In the second testcase, Eve only has jokes of the fourth type. Thus, once again no order to choose. She tells a joke, and neither Alice, nor Bob likes it. Their mood decrease by one, becoming 1-1 . They both have negative mood, thus, both leave, and the show ends.

In the third testcase, first, Eve tells both jokes of the first type. Both Alice and Bob has mood 22 . Then she can tell 22 jokes of the third type. Alice's mood becomes 00 . Bob's mood becomes 44 . Then 44 jokes of the second type. Alice's mood becomes 44 . Bob's mood becomes 00 . Then another 44 jokes of the third type. Alice's mood becomes 00 . Bob's mood becomes 44 . Then the remaining joke of the second type. Alice's mood becomes 11 . Bob's mood becomes 33 . Then one more joke of the third type, and a joke of the fourth type, for example. Alice's mood becomes 1-1 , she leaves, and the show ends.

In the fourth testcase, Eve should first tell the jokes both spectators like, then the jokes they don't. She can tell 44 jokes of the fourth type until the spectators leave.

首页