Editorial for DMOPC '15 Contest 2 P1 - Grumpy Dwarf

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.

by FatalEagle

Despite the fact that it's only the first problem, a lot of people overthought it. The intended solution is simple simulation. Keep track of the number of metal bars as well as swords we've made. Once we run out of bars, output the number of swords we've made.

bars = input()
K = input()
swords = 0
total = 0
while bars > 0:
    bars -= 1
    swords += 1
    total += 1
    if swords == K:
        bars += 1
        swords = 0
print total

Time Complexity: \mathcal{O}(N)


There are no comments at the moment.