How to optimise the Python code below

Revision en2, by kznil96, 2020-05-31 11:44:16

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 times 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)

Tags #dp, #python

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English kznil96 2020-05-31 11:44:16 22 Tiny change: 'ks/dp_b)\n([image ' -> 'ks/dp_b)\n\n([image ' (published)
en1 English kznil96 2020-05-31 11:37:52 742 Initial revision (saved to drafts)