## Troubling Times

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Alex takes the entire Komputer Kids Klub onto a field trip through time and space. Being all smart and powerful, Alex leads the club into his time machine he invented. However, since Alex is also a procrastinator, he waited until the last second, finishing the time machine just minutes before the club starts, not leaving him enough time to figure out how to make the machine work efficiently.

Alex's time machine works by jumping forward and back through time in regular intervals. For example, the time machine can be configured to jump in intervals of 4 days, which means the time machine is able to travel forward 4 days with at least 1 jump, travel forward 8 days with at least 2 jumps, or travel backward 16 days with at least 4 jumps.

Obviously tired from the hard work put into making the time machine, Alex asks you to help him determine the optimal interval to use to get to the destination time.

His time machine has different interval options that can be used, and he wishes to take the club to days into the future, whereas negative signifies travelling to the past. He wants you to tell him what is the lowest number of jumps the machine has to perform to reach . Be aware, once an interval is chosen, it cannot be changed. Also, there might be times when cannot be reached with the available intervals, in that case, output This is not the best time for a trip..

#### Input Specification

The first line of the input will contain two integers , representing the number of different interval options, and , the destination time.

The next line will contain integers denoting the length of each of the different interval option.

#### Output Specification

Output an integer , the minimum number of jumps the machine has to perform to reach , or This is not the best time for a trip. if the destination is unreachable.

#### Sample Input 1

5 -10
1 2 3 4 5

#### Sample Output 1

2

#### Explanation 1

With the interval , can be reached with jumps.

#### Sample Input 2

2 10
3 7

#### Sample Output 2

This is not the best time for a trip.

#### Explanation 2

cannot be visited no matter whether you choose or as the interval.

• commented on July 9, 2020, 1:26 p.m.

I tried doing this in Python and got ValueError, and then I did the exact same code in C++ and got AC on everything. I have no clue what's going on.

• commented on Nov. 5, 2019, 10:24 p.m.

Its 10:30 and I'm tired why am I getting WA on only one test case >:(

• commented on Sept. 25, 2017, 9:22 a.m.

komputer kids klubs 🤔

• commented on Nov. 6, 2018, 7:02 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Nov. 9, 2018, 2:27 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.