题库练习 Stand-up Comedian
← 上一题 下一题 →

A15700 | Stand-up Comedian

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

Eve prepared $a_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 $0$ . When a spectator hears a joke he/she likes, his/her mood increases by $1$ . When a spectator hears a joke he/she doesn't like, his/her mood decreases by $1$ . 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 $t$ ( $1 \le t \le 10^4$ ) — the number of testcases.

The only line of each testcase contains four integers $a_1, a_2, a_3, a_4$ ( $0 \le a_1, a_2, a_3, a_4 \le 10^8$ ; $a_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
C++ 编辑器
输入
输出