How to optimise the Python code below

Правка en1, от kznil96, 2020-05-31 11:37:52

Below is a code I wrote for Atcoder dynamic programming contest problem B. The result returns TLE for 3 out of 16 test cases.

Problem: link to problem (image of problem)

Code (python)

image of my code

The approach is just standard DP, with complexity of N.K Based on me looking around, a lot of people have submitted similar solutions with accepted verdict. Can anyone tell me why is it that the code above exceed time limit, and suggest improvements? (maybe it has to do with ways of reading input etc)

Теги #dp, #python

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский kznil96 2020-05-31 11:44:16 22 Tiny change: 'ks/dp_b)\n([image ' -> 'ks/dp_b)\n\n([image ' (published)
en1 Английский kznil96 2020-05-31 11:37:52 742 Initial revision (saved to drafts)