How to solve Topcoder SRM 536 Div 1 Medium?

During the SRM, I coded the following approach:

If the array consists of (n - 1) ones then return n. Otherwise just sum the expected value of each of the dice and round down to the nearest integer. This cleared the examples. As I could not find any case which broke the code, I submitted it. What is wrong with the approach and what is the correct approach? I tried reading others’ code but could not understand the logic.

The problem statement: http://community.topcoder.com/stat?c=problem_statement&pm=11797&rd=14728

My (wrong) solution: http://community.topcoder.com/stat?c=problem_solution&rm=311909&rd=14728&pm=11797&cr=22781250

1 Like