Algorithm


B. Combinatorics Homework
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given four integer values abc 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)(�+1)-th one).
Input

The first line contains a single integer t (1t1041≤�≤104) — the number of testcases.

Each of the next t lines contains the description of the testcase — four integers abc and m (1a,b,c1081≤�,�,�≤1080m1080≤�≤108).

Output

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 yEsyesYes and YES will all be recognized as positive answer).

Example
input
Copy
3
2 2 1 0
1 1 1 1
1 2 3 2
output
Copy
YES
NO
YES
Note

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.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    int a[3], m;
    cin>>a[0]>>a[1]>>a[2]>>m;
    sort(a, a + 3);
    int low = a[2] - 1 - (a[0] + a[1]);
    int high = a[2] + a[1] + a[0] - 3;
    (m <= high && m >= low) ? cout<<"YES"<<endl : cout<<"NO"<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
2 2 1 0
1 1 1 1
1 2 3 2

Output

x
+
cmd
YES
NO
YES
Advertisements

Demonstration


Codeforccess Solution 1574-B B. Combinatorics Homework ,C++, Java, Js and Python ,1574-B,Codeforccess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+