310168: CF1792B. Stand-up Comedian

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Stand-up Comedian

题意翻译

### 题目背景 Eve 是个单口相声新手。她的第一场表演聚集了**总计** $2$ 个观众:Alice 和 Bob。 Eve 准备了 $a_1+a_2+a_3+a_4$ 个相声表演节目。$a_i$ 表示第 $i$ 类相声的数目,每类的的特征如下: 1. Alice 和 Bob 都喜欢这类相声。 2. Alice 喜欢,Bob 不喜欢。 3. Bob 喜欢,Alice 不喜欢。 4. Alice 和 Bob 都不喜欢这类相声。 一开始,两位观众的心情**都为 $0$**。 当一位观众听到他喜欢的相声表演时心情会**加 $1$**,当听到的是自己不喜欢的相声时,心情**减 1**。 当某位观众心情**严格小于 $0$** 时,这位观众会离场。**只要有一位**这样的观众离场,Eve 会特别伤心并且结束**整个表演**。若演完了所有节目,也会结束表演。 求某种安排表演顺序的方式,使得 Eve 在**结束表演前能表演的节目最多**。输出最多能表演的节目数。 译者注:若演完某个节目有观众退场,这个节目也**算在总数之中**。 ### 输入 第一行一个整数 $t(1\le t\le 10^4)$ 表示数据组数。 对于每族数据,一行四个整数 $a_1,a_2,a_3,a_4(0\le a_1,a_2,a_3,a_4;a_1+a_2+a_3+a_4\ge 1)$,每类相声节目的数目。 ### 输出 对于每组数据一个整数表示 Eve 在结束表演前最多能表演的节目数。

题目描述

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

说明

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 $ 5 $ . 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 $ . 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 $ 2 $ . Then she can tell $ 2 $ jokes of the third type. Alice's mood becomes $ 0 $ . Bob's mood becomes $ 4 $ . Then $ 4 $ jokes of the second type. Alice's mood becomes $ 4 $ . Bob's mood becomes $ 0 $ . Then another $ 4 $ jokes of the third type. Alice's mood becomes $ 0 $ . Bob's mood becomes $ 4 $ . Then the remaining joke of the second type. Alice's mood becomes $ 1 $ . Bob's mood becomes $ 3 $ . Then one more joke of the third type, and a joke of the fourth type, for example. Alice's mood becomes $ -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 $ 4 $ jokes of the fourth type until the spectators leave.

Input

题意翻译

### 题目背景 Eve 是个单口相声新手。她的第一场表演聚集了**总计** $2$ 个观众:Alice 和 Bob。 Eve 准备了 $a_1+a_2+a_3+a_4$ 个相声表演节目。$a_i$ 表示第 $i$ 类相声的数目,每类的的特征如下: 1. Alice 和 Bob 都喜欢这类相声。 2. Alice 喜欢,Bob 不喜欢。 3. Bob 喜欢,Alice 不喜欢。 4. Alice 和 Bob 都不喜欢这类相声。 一开始,两位观众的心情**都为 $0$**。 当一位观众听到他喜欢的相声表演时心情会**加 $1$**,当听到的是自己不喜欢的相声时,心情**减 1**。 当某位观众心情**严格小于 $0$** 时,这位观众会离场。**只要有一位**这样的观众离场,Eve 会特别伤心并且结束**整个表演**。若演完了所有节目,也会结束表演。 求某种安排表演顺序的方式,使得 Eve 在**结束表演前能表演的节目最多**。输出最多能表演的节目数。 译者注:若演完某个节目有观众退场,这个节目也**算在总数之中**。 ### 输入 第一行一个整数 $t(1\le t\le 10^4)$ 表示数据组数。 对于每族数据,一行四个整数 $a_1,a_2,a_3,a_4(0\le a_1,a_2,a_3,a_4;a_1+a_2+a_3+a_4\ge 1)$,每类相声节目的数目。 ### 输出 对于每组数据一个整数表示 Eve 在结束表演前最多能表演的节目数。

Output

**单口相声新手**

**题意翻译**

### 题目背景

Eve 是个单口相声新手。她的第一场表演聚集了总计 2 个观众:Alice 和 Bob。

Eve 准备了 $a_1+a_2+a_3+a_4$ 个相声表演节目。$a_i$ 表示第 $i$ 类相声的数目,每类的的特征如下:

1. Alice 和 Bob 都喜欢这类相声。

2. Alice 喜欢,Bob 不喜欢。

3. Bob 喜欢,Alice 不喜欢。

4. Alice 和 Bob 都不喜欢这类相声。

一开始,两位观众的心情都为 $0$。

当一位观众听到他喜欢的相声表演时心情会加 $1$,当听到的是自己不喜欢的相声时,心情减 $1$。

当某位观众心情严格小于 $0$ 时,这位观众会离场。只要有一位这样的观众离场,Eve 会特别伤心并且结束整个表演。若演完了所有节目,也会结束表演。

求某种安排表演顺序的方式,使得 Eve 在结束表演前能表演的节目最多。输出最多能表演的节目数。

译者注:若演完某个节目有观众退场,这个节目也算在总数之中。

### 输入

第一行一个整数 $t(1\le t\le 10^4)$ 表示数据组数。

对于每族数据,一行四个整数 $a_1,a_2,a_3,a_4(0\le a_1,a_2,a_3,a_4;a_1+a_2+a_3+a_4\ge 1)$,每类相声节目的数目。

### 输出

对于每组数据一个整数表示 Eve 在结束表演前最多能表演的节目数。

**题目描述**

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
```

**说明**

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 $ 5 $ . 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 $ . 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 $ 2 $ . Then she can tell $ 2 $ jokes of the third type. Alice's**单口相声新手** **题意翻译** ### 题目背景 Eve 是个单口相声新手。她的第一场表演聚集了总计 2 个观众:Alice 和 Bob。 Eve 准备了 $a_1+a_2+a_3+a_4$ 个相声表演节目。$a_i$ 表示第 $i$ 类相声的数目,每类的的特征如下: 1. Alice 和 Bob 都喜欢这类相声。 2. Alice 喜欢,Bob 不喜欢。 3. Bob 喜欢,Alice 不喜欢。 4. Alice 和 Bob 都不喜欢这类相声。 一开始,两位观众的心情都为 $0$。 当一位观众听到他喜欢的相声表演时心情会加 $1$,当听到的是自己不喜欢的相声时,心情减 $1$。 当某位观众心情严格小于 $0$ 时,这位观众会离场。只要有一位这样的观众离场,Eve 会特别伤心并且结束整个表演。若演完了所有节目,也会结束表演。 求某种安排表演顺序的方式,使得 Eve 在结束表演前能表演的节目最多。输出最多能表演的节目数。 译者注:若演完某个节目有观众退场,这个节目也算在总数之中。 ### 输入 第一行一个整数 $t(1\le t\le 10^4)$ 表示数据组数。 对于每族数据,一行四个整数 $a_1,a_2,a_3,a_4(0\le a_1,a_2,a_3,a_4;a_1+a_2+a_3+a_4\ge 1)$,每类相声节目的数目。 ### 输出 对于每组数据一个整数表示 Eve 在结束表演前最多能表演的节目数。 **题目描述** 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 ``` **说明** 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 $ 5 $ . 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 $ . 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 $ 2 $ . Then she can tell $ 2 $ jokes of the third type. Alice's

加入题单

算法标签: