Consider the minimum possible answer. Since you have to do all $$$s$$$ problems in $$$n$$$ days, you can do $$$\lfloor \frac s n \rfloor$$$ in some of them and then $$$\lceil \frac s n \rceil$$$ in the rest of the days. Thus, $$$\lceil \frac s n \rceil$$$ is the minimum possible $$$a_n$$$.
Now it would be great if the function that tells if some $$$x$$$ can be the number of problems during the last day was monotonous for all $$$x$$$ from $$$\lceil \frac s n \rceil$$$ to $$$\infty$$$. So that function first returns true for some prefix of values, then it returns false. Intuitively, it sounds monotonous: the smaller values allow a lot of freedom for the construction and the larger values fail because they require too many problems in total.
The difficulty rises from the fact we not only have to prove that, but we also have to find a way to ask the result of that function quickly.
If we didn't have to, the proof would not be too hard.
ProofConsider some distribution of $$$s$$$ problems such that the last element is $$$x>\lceil \frac s n \rceil$$$. Let's move some problems around to make the last element $$$x-1$$$. So there is a block of days with $$$x$$$ problems at the end. There also is a block of days with the number of problems equal to the first day. You can always move the problem from the first day of the ending block to the last day of the beginning block.
Let's call the first day of the ending block $$$r$$$ and the last day of the beginning block $$$l$$$. Observe that the condition between $$$r-1$$$ and $$$r$$$ never breaks. Since the difference between $$$a_{r-1}$$$ and $$$a_r$$$ decreased, if it was two-fold or less then it's still two-fold or less. Same for $$$l$$$ and $$$l+1$$$. In the case of $$$l=r-1$$$, the difference between $$$a_l$$$ and $$$a_r$$$ must have been at least $$$2$$$, thus, $$$a_l \le a_r$$$ after the move. The difference can't be $$$1$$$ because then it is exactly the same construction we have built for the minimum case, thus $$$x=\lceil \frac s n \rceil$$$. The condition between $$$r$$$ and $$$r+1$$$ also can't break. If $$$r$$$ is the last day, then there is no $$$r+1$$$. Otherwise, $$$a_r$$$ becomes equal to $$$a_{r+1} - 1$$$. Since all the values are positive, that difference can't become above two-fold. Same reasoning goes for $$$l$$$ and $$$l-1$$$.
So that move is always valid. That move also decreases the size of the ending block by $$$1$$$. Thus, at some point the ending block will be of size $$$1$$$, so making a move from it will decrease the last value by $$$1$$$. That proves that for any $$$x$$$ that can be the last value, $$$x-1$$$ can also be the last value. Thus, the function is indeed monotonous.
Now that we are absolutely sure that the function is monotonous, let's change our approach.
Obviously, we should try binary search on $$$x$$$. So we have the total number of problems $$$s$$$, the number of days $$$n$$$ and some fixed number of problems during the last day $$$x$$$.
Our second educated guess can be of the following kind. Given fixed $$$n$$$ and $$$x$$$, all the possible values of $$$s$$$ that can correspond to some construction are some segment of integers. That can actually be proven in the similar manner.
ProofConsider the smallest value of $$$s$$$ that can be obtained: the last day has $$$x$$$ problems, the second to last has $$$\lceil \frac x 2 \rceil$$$ and so on.
In any construction there is a block of days with the number of problems equal to the first day. You can always add a problem to the last day of that block, thus increasing the total number of problems by $$$1$$$. The casework is basically the same as in the first proof.
That construction also implies that the smallest value of $$$s$$$ grows as $$$x$$$ grows.
So we can binary search for a solution for $$$x$$$ from $$$\lceil \frac s n \rceil$$$ to $$$s$$$. $$$f(x)$$$ can be the smallest total number of problems such that there exists a distribution. Since that value is monotonous, you can look for the largest $$$x$$$ such that $$$f(x) \le s$$$.
To calculate the function you can observe that the sequence $$$x$$$, $$$\lceil \frac x 2 \rceil$$$, $$$\left\lceil \frac{\lceil \frac x 2 \rceil}{2} \right\rceil$$$, $$$\dots$$$ has only ones after $$$\log(x)$$$ values.
Overall complexity: $$$O(\log^2 s)$$$ per testcase.
The solution codes will be uploaded shortly.
UPD: here they are.
When will the Random T-shirt winners will be announce?
Problem E seems to be well-known after you realize that it's the LCS of $$$a$$$ and its reverse, and the number of matches between the two strings is in $$$O(n)$$$. If the problem is strengthened to having at most $$$k$$$ occurrences of each integer, the problem can be solved in $$$O(k n \log n)$$$ time.
Wow, nice observation, I just completely overkilled this.
can you tell name of algo or provide some link for "how to find no of match between two strings in O(n)"
To find the number of elements in string $$$B$$$ that match with a given element of string $$$A$$$, simply do this:
Construct the frequency array/map of $$$B$$$, and then for each element in $$$A$$$, simply read off the number of elements in $$$B$$$ that match with it.
However, this was not what I meant by the comment above. I meant that if $$$B$$$ is the reverse of $$$A$$$, the number of matches between $$$A$$$ and $$$B$$$ (defined as the sum of the elements found in the above algorithm) is upper bounded by some constant multiple of $$$n$$$, and if the maximum frequency of an element of $$$A$$$ is $$$k$$$, then an explicit upper bound is $$$nk$$$.
In general, if there are at most $$$m$$$ matches between two strings, you can figure out an algorithm to find the LCS in $$$O((m + n) \log n)$$$.
1488C - Two Policemen can be solved in $$$\mathcal{O}(\log n)$$$ time via binary search.
In an optimal solution, the left policeman (at $$$l$$$) will visit $$$[1,m]$$$ while the right policeman (at $$$r$$$) will visit $$$[m+1,n]$$$.
With this in our mind, we can binary search for the total time.
The lower bound is $$$\max(l-1, n-r)$$$ since the left policeman needs to cover $$$1$$$, while the right policeman needs to cover $$$n$$$. And the upper bound is $$$n$$$ since in any case, they would need no more than $$$n$$$ minutes to finish.
Now for a given time $$$T$$$, we can find the largest position $$$r_l$$$ that the left policeman can cover, and the smallest position $$$l_r$$$ that the right policeman can cover.
Then if
it is possible to cover all positions within $$$T$$$ time.
Otherwise, we cannot cover.
Code: 109510140
A screencast with video solutions if you're into those... and also the first one with a facecam
For J: you can remove the $$$\log MX$$$ term because the polynomials we care about are all geometric sums, so you can take the Fourier transform in $$$O(MX)$$$ time by precomputing powers of the root of unity.
In problem E, For even length palindromic subsequences, how can the answer be found from longest decreasing subsequence of second occurrences.
If a = [4,3,2,1,1,2,3,4] Then the answer should be 8 but finding longest decreasing subsequence of second occurrences will not provide that answer.
You would need to re-enumerate all elements of $$$a$$$ according to the index of the first time they appear. More formally, if $$$i(x)$$$ is the first index such that $$$a[i(x)] = x$$$, then construct an array defined by $$$b[j] = i(a[j])$$$.