Codeforces 1183C. Computer Game Codeforces Round #570 (Div. 3)


Problem link

Firstly, about the problem description. Vova really needs to complete the game i. e. play all n turns. Exactly n turns. Among all possible ways to do it, he needs to use one where the number of turns when he just plays (this is the first type turn!) is maximum possible.

Suppose the answer is n. Then the charge of the battery after n turns will be c=k−na. If this value is greater than 0 then the answer is n. Otherwise,we need to replace some turns when Vova just plays with turns when Vova plays and charges. The charge of the battery will increase by diff=a−b avfter one replacement. We have to obtain c>0 with some replacements. The number of turns to do it is equals to turns=⌈−c+1diff⌉, where ⌈xy⌉ is x divided by y rounded up. If turns>n then the answer is -1. Otherwise the answer is n−turns.

A solution in c++



Post a Comment

0 Comments