1574B.md (1487B)
1 Source: https://codeforces.com/problemset/problem/1574/B 2 3 B. Combinatorics Homework 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given four integer values $a$, $b$, $c$ and $m$. 22 23 Check if there exists a string that contains: 24 25 * $a$ letters 'A'; 26 * $b$ letters 'B'; 27 * $c$ letters 'C'; 28 * no other letters; 29 * 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). 30 31 Input 32 33 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. 34 35 Each of the next $t$ lines contains the description of the testcase — four integers $a$, $b$, $c$ and $m$ ($1 \le a, b, c \le 10^8$; $0 \le m \le 10^8$). 36 37 Output 38 39 For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings. 40 41 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). 42 43 Example 44 45 Input 46 47 ``` 48 3 49 2 2 1 0 50 1 1 1 1 51 1 2 3 2 52 ``` 53 54 Output 55 56 ``` 57 YES 58 NO 59 YES 60 ``` 61 62 Note 63 64 In the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings. 65 66 In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice. 67 68 In the third testcase string "CABBCC" satisfies the requirements. There exist other possible strings.