Editorial for CTU Open Contest 2017 - Amusement Anticipation
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
- Naive solution sufficed – for each index
of the array, check whether it is a start of an arithmetic sequence
by iterating through all of its elements
- The smallest such index is the result
- This approach runs in
time
- However, last two numbers of the array are always contained in the optimal arithmetic sequence ending at index
⇒ the difference
of the optimal sequence is
(for
)
- It then suffices to check, starting from the end of the array, how many numbers correspond to the difference
- The first index
, s.t.
, is the result (or if no such index exists, the whole array is an arithmetic sequence)
- This approach yields an
solution
Comments