Can Peter-III Save "MJ" This Time?

anisur_rahman DIU Take-off Programming...
Limits 1s, 512 MB

Peter-I returns to Dr.Strange as he prepares to use the Macchina to send everyone home. Suddenly, Green Goblin Attacks the spiderman’s group and takes the Macchina from MJ, but Dr.Otto Octavius and Dr.Strange grab it back.

Unknowingly to them, Green-Goblin had snuck a Pumpkin Bomb inside the Macchina. It detonates and releases the unstable contained spell, tearing the fabric of the universe and opening it up to the Multiverse. The blast also causes MJ to fall from the Statue of Liberty. Peter-I dives to rescue her but is knocked aside by Green-Goblin.

At that moment Peter-III notices that and Jumps shooting his web-shooters to save MJ. Unfortunately, his web-shooter is not as advanced as Peter-I. The main weakness of his web-shooter is that he has a limited number of webs in that and can only shoot at most two of the webs from his web list. If the sum of two web lengths is greater than or equal to the distance from Peter-III to MJ then Peter-III can save MJ otherwise she will die. Can Peter-III Save "MJ" This Time?


The first line contains two integers where N denotes the number of webs Peter-III have and D denotes the distance between Peter-III and “MJ”.
The next line contains N separated integers which denote the length of the i-th web as w[i].

2N1032 \leq N \leq 10^3

0D1060 \leq D \leq 10^6

0w[i]1030 \leq w[i] \leq 10^3


The first and only line of output consists of one string. If Peter-lll can save MJ, print "YES", otherwise, print "NO" without the quotations.


5 10
1 2 3 4 4

There are no two web-shooters whose sum of length is greater or equal to D=10.

9 14
8 8 9 3 5 1 9 9 7

If Peter-III chooses from web-shooters as w[1] and w[9] then w[1]+w[9]=(8+7)=15>=D.
so, we say that Peter-III can save MJ.


Login to submit.


92% Solution Ratio
abu_fayeemEarliest, Mar '22
sodiumfis_hFastest, 0.0s
abu_fayeemLightest, 131 kB
Sudipto.553166Shortest, 213B
Toph uses cookies. By continuing you agree to our Cookie Policy.