CF1574B.Combinatorics Homework
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given four integer values a, b, c and m.
Check if there exists a string that contains:
- a letters 'A';
- b letters 'B';
- c letters 'C';
- no other letters;
- exactly m pairs of adjacent equal letters (exactly m such positions i that the i-th letter is equal to the (i+1)-th one).
给你四个整数 a、b、c 和 m。
请判断是否存在一个字符串,满足以下条件:
- 包含 a 个字母 'A';
- 包含 b 个字母 'B';
- 包含 c 个字母 'C';
- 不包含其他任何字母;
- 恰好有 m 对相邻且相等的字母(即恰好有 m 个位置 i,使得第 i 个字母等于第 (i+1) 个字母)。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
Each of the next t lines contains the description of the testcase — four integers a, b, c and m (1≤a,b,c≤108; 0≤m≤108).
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
接下来的 t 行,每行描述一个测试用例,包含四个整数 a、b、c 和 m(1≤a,b,c≤108;0≤m≤108)。
输出格式
For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
对于每个测试用例,如果存在满足所有要求的字符串,则输出 “YES”;如果不存在这样的字符串,则输出 “NO”。
你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均会被识别为肯定回答)。
输入输出样例
输入#1
3 2 2 1 0 1 1 1 1 1 2 3 2
输出#1
YES NO YES
说明/提示
In the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings.
In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice.
In the third testcase string "CABBCC" satisfies the requirements. There exist other possible strings.
在第一个测试用例中,字符串 “ABCAB” 或 “BCABA” 满足要求。还存在其他可能的字符串。
在第二个测试用例中,若没有任何字母出现至少两次,则无法放置相邻的相同字母。
在第三个测试用例中,字符串 “CABBCC” 满足要求。还存在其他可能的字符串。
输入解题思路,AI测评打分。不知道怎么写?