Comments

specifically, the remainder is staying the same also after 2*x>y since both x and y are increasing by 1.

And regardless of how big k is, it won't take more than 10**6 iterations for 2*x > y since initial x and y are bounded by 10**6. Need some algebra for the proof.

if you want to know read this:

after 2*x > y, the remainder will always be the same for y%x as they both only increase by 1 and x will never divide into y evenly after that. Not the best proof but that's how I thought of it.

Dang... I'm happy I got to the point of F of getting every possible skill to be at n-2, n-4, n-6 etc. then to be at n-4, n-8, n-12 etc. but that ends up being over 2 million cost. Didn't know how to get the right segment length / layer / modulo / power, though I started trying to write a function to minimize.

Isn't D basically just finding the distance of each number to the median? (https://codeforces.me/contest/2157/submission/350333441)

That's what I did, with the exception that if the median is outside the range of l <= x <= r, then you set this target median as l or r, whichever is closer, since that's the closest value to each value in the array while still being in the possible range.

I guess it's kind of said in the editorial with "The worst case is either x=l or x=r"

I think I did something somewhat similar as an O(N) solution in python (https://codeforces.me/contest/2157/submission/350347513)

I keep track of consecutive operations needed (operating on 1, 2, 3 etc.) and keep comparing to maxOps and if there's a point where I don't need to operate then I reset ops to 0. In order to simulate this correctly, I have to propagate i+1 to i+2 if needed before I propagate i to i+1. Then when you hit the max freq (plus like 1 or 2) that you could have at the start, then just add that final freq — 1 to your answer so you don't have to simulate to TLE.

I only made my freq array 2*n, but effectively same complexity

yeah... I didn't solve G but pretty sure I already know how to do it without looking at editorial. But I got stuck doing F not knowing how to quickly sum all the costs/contributions. Should've done G instead.

I did something similar (or maybe the same) that worked. I found the node that has the most leaves attached. Then the answer was the {total number of leaves} minus {most leaves on one node}.

I did that too lol. But after the contest, and in Python. Only had 8 minutes left when I got to that question so I basically just wrote out my notes and watched the clock tick down.

Submission