Who Gets Her
All submissions for this problem are available.
Amogh decides to go to Delhi to meet someone, and starts off in a train from his city. Seeing this, Sameer decides to go too (for obvious reasons). But he doesn't like to travel by train. So he decides to do a bus-journey.
Sameer lives in Nashik. There are N cities between Nashik and Delhi (including Delhi but excluding Nashik), and in each city there are M buses numbered 1 to M. Sameer needs to travel to Delhi following these conditions:
1. At every city, he needs to change the bus.
2. At every city, he can switch to only those buses which have number either equal to, or 1 less than, or 1 greater than the previous.
Also, a bus takes him from the present city to the next city, not beyond that.
You are given the time (T) required by Amogh to reach Delhi, and the time required by all buses to reach the next city from the current city.
Can Sameer reach Delhi before Amogh?
First line contains k, the number of testcases. k testcases follow. Each testcase is described as:
Line 1: T
Line 2: N,M
The next N lines contain time taken by M buses to go to the next city.
Output a single line saying "YES" or "NO" (without quotes), indicating whether Sameer can reach Delhi before Amogh or not.
- 1 ≤ T ≤ 100
- 1 ≤ N,M ≤ 500
Input: 1 14 5 5 1 3 1 2 6 10 2 5 4 15 10 9 6 7 1 2 7 1 5 3 8 2 6 1 9
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, PERL, FORT, ADA, ASM, PRLG, SCM qobi, PIKE, BASH, LISP sbcl, LISP clisp, SCM guile, JS, PERL6, TEXT|
Fetching successful submissions