Need help in figuring out to how to fix TLE issue in my submission.

Правка en3, от CrypticTaiga, 2020-07-27 16:13:28

Problem — Problem

Submission — My Submission

I tried to solve the problem by taking the calculating the costs from all indexes starting from 0 upto n-1, and finally comparing the cost with the value of p. This is failing for large testcases (like number 5) and I am getting TLE.

Can you help me figure out how to make a dp array to save the precalculated costs for a prefix of length i at index i and then use to to calculate the cost for the prefix of size (i + 1). I tried but mine approach is not working correctly.

Thanks!

Теги #java8, #dp, #algorithms, #data structures

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский CrypticTaiga 2020-07-27 16:13:28 104
en2 Английский CrypticTaiga 2020-07-27 15:55:29 47
en1 Английский CrypticTaiga 2020-07-27 15:54:36 617 Initial revision (published)