Educational Codeforces Round 114 (Rated for Div. 2)B. Combinatorics Homework(抽屉原理)

什么是抽屉原理:建议看这篇博客,好详细的。

链接icon-default.png?t=LBL2https://blog.csdn.net/zx1772874955/article/details/109902831?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.no_search_link&utm_relevant_index=11

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 aa, bb, cc and mm.

Check if there exists a string that contains:

  • aa letters 'A';
  • bb letters 'B';
  • cc letters 'C';
  • no other letters;
  • exactly mm pairs of adjacent equal letters (exactly mm such positions ii that the ii-th letter is equal to the (i+1)(i+1)-th one).

Input

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

Each of the next tt lines contains the description of the testcase — four integers aa, bb, cc and mm (1≤a,b,c≤1081≤a,b,c≤108; 0≤m≤1080≤m≤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 yEs, yes, Yes 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.

 题意:a个A,b个B,c个C,能不能搞出一个字符串使其有m个两两相邻的字母。

maxx=a[1]+a[2]+a[3]-3 是最多的情况。

minn=max(0,a[3]-a[2]-a[1]-1)是最少的。

maxx和minn是两个极端。

刚开始想的很简单,a,b,c,只要大于等于2,就能组成相邻的,然后把相邻的个数++,最后和m比大小,结果第二个点就wa。

//#include<bits/stdc++.h>
//using namespace std;
//int t,a,b,c,m,k;
//int main(){
//	cin>>t;
//	while(t--){
//		cin>>a>>b>>c>>m;
//		if(a>=2){
//			k++;
//		}if(b>=2){
//			k++;
//		}if(c>=2){
//			k++;
//		}if(k>=m){
//			cout<<"YES"<<endl;
//		}else{
//			cout<<"NO"<<endl;
//		}k=0;
//	}
//} 
#include<bits/stdc++.h>
using namespace std;
int a[5],i,j,k,m;
int main(){
	cin>>k;
	while(k--){
		cin>>a[1]>>a[2]>>a[3]>>m;
		sort(a+1,a+4);
		int maxx=a[1]+a[2]+a[3]-3;
		int minn=max(0,a[3]-a[2]-a[1]-1);
		if(maxx>=m&&minn<=m){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值