Codeforces has easy and tough questions. However, the easy are not always easy, but the tough are always tough. Thus, after writing the Excel article here for Sumproduct, I have decided to go a bit easy and start with the first problem of Round 421. It should be a simple implementation problem, but still good enough for a warm up.

*Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.*

*At first day Mister B read v _{0} pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_{0} pages, at second — v_{0} + a pages, at third — v_{0} + 2a pages, and so on). But Mister B is just a human, so he physically wasn’t able to read more than v_{1} pages per day.*

*Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.*

*Help Mister B to calculate how many days he needed to finish the book.*

*Input*

*First and only line contains five space-separated integers: c, v _{0}, v_{1}, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v_{0} ≤ v_{1} ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.*

*Output*

*Print one integer — the number of days Mister B needed to finish the book.*

The trick here is to understand the solution – the guy should keep on reading until he has read the whole book. That’s an obvious While(True) loop. Concerning the acceleration, there is an easy way to do it, if you have some OOP experience – simply always accelerate and make a check for the maximum acceleration. If it is above the maximum, then assign the maximum. Last but not least – we have 2 cases – the first day and every other day. Thus a condition would work there well. Pretty much, my whole code is explained in the previous 3 sentences. Enjoy it:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Startup { static void Main() { int[] intArrInput = ReadLineAndParseToArray(); int intLengthOfBook = intArrInput[0]; int intInitialReading = intArrInput[1]; int intMaxReadingSpeed = intArrInput[2]; int intAcceleration = intArrInput[3]; int intReadAgain = intArrInput[4]; int intPagesRead = 0; int intDays = 0; while (intPagesRead<intlengthofbook) {="" intdays++;="" if="" (intdays!="1)" intinitialreading="" +="intAcceleration;" (intinitialreading="">intMaxReadingSpeed) intInitialReading = intMaxReadingSpeed; intPagesRead += intInitialReading; intPagesRead -= intReadAgain; } else { intPagesRead = intInitialReading; } } Console.WriteLine(intDays); } public static int[] ReadLineAndParseToArray() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } } |

Cheers! 🙂