Combinatorics Homework 思维

判断最大值和最小值,看给的数值是否位于区间中。

// Problem: B. Combinatorics Homework
// Contest: Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1574/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
using namespace std;
#define ff first
#define ss second
#define lowbit(x) (x&-x)
#define pf(a) printf("%d\n",a)
#define mem(x,y) memset(x,y,sizeof(x))
#define dbg(x) cout << #x << " = " << x << endl
#define rep(i,l,r) for(int i = l; i <= r; i++)
#define fep(i,a,b) for(int i=b; i>=a; --i)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

const int inf=0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N=1e5+100;


void solve()
{
	int a, b, c, m;
	cin >> a >> b >> c >> m;
	
	int M = max({a,b,c}); // 最大值
	
	int all = a + b + c - M; // 剩下的两个值
	
	int Min = 0;
	
	if(M - 1 <= all)  Min = 0; // 如果能插空,则必定可以使得没有连对
	else Min = M-1 -all; // 否则 剩下的形成连对
	
	//cout << Min << endl;
	
	int Max = a-1 + b-1 + c-1; //  形成最多的连对
	
	bool f = true;
	
	if(Max >= m and Min <= m) f = true; // 连对位于区间中,可以实现,否则不可以实现
	else f = false;
	
	if(f) printf("YES\n");
	else printf("NO\n");
}

int main()
{
	int Case;scanf("%d", &Case);
	while(Case--)
		solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值