DOTAA - DOTA HEROES

no tags 

Defence Of The Ancients (DOTA) is one of the most addictive online multiplayer games. There are n heroes in our team and our motto is to conquer the opponent’s empire. To safeguard their empire, the opponents had constructed m towers on the path. If one or more heroes get into the sight of a tower, then the tower does D amount of damage to one of those heroes at that instant (i.e. one of the heroes’ health decreases by D). Any hero will die if his health H <= 0. Once a tower attacks one of the heroes, all the heroes in the sight of that tower at that instant get out of its sight. Find whether all of the heroes in our team can reach the opponent’s empire alive.

Input

The first line consists of one integer t representing the number of test cases. For each test case, the first line consists of three integers n, m and D, the number of heroes, number of towers and the amount of Damage respectively. The next n lines consist of an integer representing the health of respective hero.

Output

Just a word “YES” if we can reach the opponent’s empire alive, else “NO”.

Constraints

1 <= t <= 500
1 <= n <= 500
1 <= m <= n
1 <= D, H <= 20000

Example

Input:
3
6 3 400
500
500
500
500
500
500
6 5 400
800
800
801
200
200
200
6 3 400
401
401
400
200
400
200

Output:
YES
NO
NO

Explanation of test case 1:

One of the possible solutions is: First, three of the heroes can goes together. One of them receives 400 damage from the first tower and all of them cross it. Then while crossing the next tower, one of the heroes who is at 500 health gets 400 damage and all of them cross it. Then the third hero receives the damage when crossing the last tower. Similarly the other 3 heroes can reach the opponent’s base together without dying.


hide comments
Archit Kapoor: 2015-02-26 12:32:20

I finally realized the importance of an "is equal to"(=), i.e. a comparison operator which I was missing out in my last 3 submissions could be of so much importance, but finally got AC in my 4th submission. An easy question, be careful from committing silly mistakes like I did..!!

Last edit: 2015-02-26 12:33:33
Anvesh Kumar Arrabochu: 2015-01-15 09:16:38

Input:
6 3 400
1201
200
200
200
200
200
Output: YES

Sumit Paroothi: 2014-12-18 14:15:04

ac with O(N^2)

Sarthak Taneja: 2014-12-14 15:17:41

Why am I getting wrong answer?
I applied logic that if atleast m heroes have health greater than D then YES else NO

Madhur Bhargava: 2014-10-12 05:52:45

Simple logic.
@ashish kumar yogi Thanks a lot. Your test case helped.

Gaurav Ahirwar: 2014-09-24 19:58:39

easiest! :)

mohsin mohammad: 2014-08-12 18:13:01

My 92nd....

-.-: 2014-08-09 00:16:39

did this problem in O(n).. used fast i/o still i got ac in 0.14 :/
is there any O(1) solution? there are 0.01s ac.

sobriquet: 2014-08-07 20:10:29

O(n) solution, please read the following comment by

@:D

Problem description is a little confusing.

Last edit: 2019-12-06 21:42:55
Darren Sun: 2014-07-26 04:22:13

@Vikrant Singh
Most probably, the culprit is your algorithm (less possibly, your I/O methods). It can actually be solved with O(n) time and O(1) space for each test case.


Added by:cegprakash
Date:2011-12-25
Time limit:0.208s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: BF