Replacing Elements

CodeForces - 1473A

You have an array a1,a2,…,an. All ai are positive integers.

In one step you can choose three distinct indices i, j, and k (i≠j; i≠k; j≠k) and assign the sum of aj and ak to ai, i. e. make ai=aj+ak.

Can you make all ai lower or equal to d using the operation above any number of times (possibly, zero)?

Input
The first line contains a single integer t (1≤t≤2000) — the number of test cases.

The first line of each test case contains two integers n and d (3≤n≤100; 1≤d≤100) — the number of elements in the array a and the value d.

The second line contains n integers a1,a2,…,an (1≤ai≤100) — the array a.

Output
For each test case, print YES, if it’s possible to make all elements ai less or equal than d using the operation above. Otherwise, print NO.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

Example
Input
3
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6
Output
NO
YES
YES
Note
In the first test case, we can prove that we can’t make all ai≤3.

In the second test case, all ai are already less or equal than d=4.

In the third test case, we can, for example, choose i=5, j=1, k=2 and make a5=a1+a2=2+1=3. Array a will become [2,1,5,3,3].

After that we can make a3=a5+a2=3+1=4. Array will become [2,1,4,3,3] and all elements are less or equal than d=4.

题解

直接找出最小的两个,判断是否<=d就行,还有一种情况是最小的两个>d但是所有都<=d

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{ll n,q,d;ll cb[1000],cb2[1000];cin>>n;for(ll i=1 ; i<=n ; i++){memset(cb2,0,sizeof(cb2));cin>>q>>d;for(ll j=1 ; j<=q ; j++){cin>>cb[j];}int cnt = 0;for(ll j=1 ; j<=q ; j++){for(ll k=j+1 ; k<=q ; k++){if(cb[j]+cb[k] <= d){cnt = 1;break;}}}if(cnt == 0){int qq = 1;for(ll j=1 ; j<=q ; j++){if(cb[j]>d){qq = 0;}}if(qq){cnt = 1;}}if(cnt == 1){cout<<"YES\n";}else{cout<<"NO\n";}}} 

Replacing Elements相关推荐

  1. Replacing Elements (CodeForces - 1473A)

    Replacing Elements You have an array a1,a2,-,an. All ai are positive integers. In one step you can c ...

  2. Angular component的一个例子

    官网:https://angular.io/guide/architecture-components Before a view is displayed, Angular evaluates th ...

  3. python设置堆大小_Python中的堆问题

    Heap in python 堆(英语:Heap)是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因为实际情况中某些时 ...

  4. 《泛型编程与stl》

    以下是STL六大组件(componments): adapters  配接器 用来修饰其他组件.包括iterator adapters.function  adapters.container ada ...

  5. 【CF比赛】Educational Codeforces Round 102 (Rated for Div. 2)

    题目来源 Educational Codeforces Round 102 (Rated for Div. 2) A. Replacing Elements 只要判断最大值是否小于等于d,或者第一个值 ...

  6. Mixed Finite Elements for Variational Surface Modeling

    paper source { formula 5 LB=12<v,v>Ω0+<λ,Δu−v>Ω0=12<v,v>Ω0−<λ,v>Ω0+<λ,Δu& ...

  7. AtCoder Beginner Contest 171 D - Replacing

    D - Replacing Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement You ...

  8. vue/require-v-for-key]Elements in iteration expect to have ‘v-bind:key‘ directives

    报错内容:[vue/require-v-for-key]Elements in iteration expect to have 'v-bind:key' directives.解决:加上v-bind ...

  9. Robotium todolist.test.elements

    2019独角兽企业重金招聘Python工程师标准>>> ElementsEditToDoItemActivity package com.example.todolist.test. ...

最新文章

  1. SQL Server 数据库备份
  2. python迭代器面试题_Python面试题之生成器/迭代器
  3. 金山电子表格金山电子表格为何会死机?
  4. mysql 分区指定路径_[数据库]MySQL 指定各分区路径
  5. HDU-1170的解题报告
  6. Spring核心(ioc控制反转)
  7. ios点击推送闪退_苹果推送iOS 14.2 beta 1:千万别更新,大批应用闪退
  8. JavaScript每日学习日记(2)
  9. 173. 二叉搜索树迭代器/94. 二叉树的中序遍历/145. 二叉树的后序遍历/98. 验证二叉搜索树
  10. java登陆session用法_java中session用法
  11. [转].net中的认证(authentication)与授权(authorization)
  12. 机器学习(11): FP-growth算法 小结及实验
  13. 网页中使用iconfont图标
  14. Flutter 启动页 消除白屏
  15. 唯一分解之Pollard-Rho算法
  16. 一文搞懂考研数列极限问题(概念/计算/证明)史上最强/最全总结
  17. 10min快速了解k8s基础
  18. SRS流媒体服务器——服务器读取RTMP推流数据
  19. 架构设计文档提纲简描
  20. py sel采集部署linux报错

热门文章

  1. 人工智能Java SDK:声纹识别
  2. 友宝:掘金生活物联网
  3. WebStorm下载及破解
  4. 用Python爬取微信好友头像,才知道好友都是这样的人
  5. 截止频率计算公式wc_已知低通滤波器的传递函数是G(s)=(G0*Wc)/(s+Wc),截止频率不超过2HZ,怎么求?...
  6. 一文带你深入了解Linux IIO 子系统
  7. opencv remap matlab,C++ Opencv remap()重映射函数详解及使用示例
  8. GraphicsLab Project之基于物理的着色系统(Physical based shading) - 基于图像的光照(Image Based Lighting)(Diffuse篇)
  9. Python0019 音频处理(二).wav文件
  10. 行列式【线性代数系列(一)】