CF1680A.Minimums and Maximums
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An array is beautiful if both of the following two conditions meet:
- there are at least l1 and at most r1 elements in the array equal to its minimum;
- there are at least l2 and at most r2 elements in the array equal to its maximum.
For example, the array [2,3,2,4,4,3,2] has 3 elements equal to its minimum (1-st, 3-rd and 7-th) and 2 elements equal to its maximum (4-th and 5-th).
Another example: the array [42,42,42] has 3 elements equal to its minimum and 3 elements equal to its maximum.
Your task is to calculate the minimum possible number of elements in a beautiful array.
如果一个数组同时满足以下两个条件,则称其为“优美的”:
- 数组中等于其最小值的元素个数至少为 l1,至多为 r1;
- 数组中等于其最大值的元素个数至少为 l2,至多为 r2。
例如,数组 [2,3,2,4,4,3,2] 中,有 3 个元素等于其最小值(第 1、3、7 个元素),有 2 个元素等于其最大值(第 4、5 个元素)。
另一个例子:数组 [42,42,42] 中,有 3 个元素等于其最小值,也有 3 个元素等于其最大值。
你的任务是计算一个优美数组可能包含的最少元素个数。
输入格式
The first line contains one integer t (1≤t≤5000) — the number of test cases.
Each test case consists of one line containing four integers l1, r1, l2 and r2 (1≤l1≤r1≤50; 1≤l2≤r2≤50).
第一行包含一个整数 t(1≤t≤5000)—— 测试用例的数量。
每个测试用例由一行组成,包含四个整数 l1、r1、l2 和 r2(1≤l1≤r1≤50;1≤l2≤r2≤50)。
输出格式
For each test case, print one integer — the minimum possible number of elements in a beautiful array.
对于每个测试用例,输出一个整数——美丽数组中元素的最小可能数量。
输入输出样例
输入#1
7 3 5 4 6 5 8 5 5 3 3 10 12 1 5 3 3 1 1 2 2 2 2 1 1 6 6 6 6
输出#1
4 5 13 3 3 3 6
说明/提示
Optimal arrays in the test cases of the example:
- [1,1,1,1], it has 4 minimums and 4 maximums;
- [4,4,4,4,4], it has 5 minimums and 5 maximums;
- [1,2,1,2,2,1,2,2,2,2,2,2,2], it has 3 minimums and 10 maximums;
- [8,8,8], it has 3 minimums and 3 maximums;
- [4,6,6], it has 1 minimum and 2 maximums;
- [3,4,3], it has 2 minimums and 1 maximum;
- [5,5,5,5,5,5], it has 6 minimums and 6 maximums.
示例测试用例中的最优数组:
- [1,1,1,1],它有 4 个最小值和 4 个最大值;
- [4,4,4,4,4],它有 5 个最小值和 5 个最大值;
- [1,2,1,2,2,1,2,2,2,2,2,2,2],它有 3 个最小值和 10 个最大值;
- [8,8,8],它有 3 个最小值和 3 个最大值;
- [4,6,6],它有 1 个最小值和 2 个最大值;
- [3,4,3],它有 2 个最小值和 1 个最大值;
- [5,5,5,5,5,5],它有 6 个最小值和 6 个最大值。
输入解题思路,AI测评打分。不知道怎么写?