I'm sorry for the delay, it took some time for me to translate analysis to English.

Tutorial is loading...

Problem author: KAN, preparation: KAN.

Tutorial is loading...

Problem author: KAP, preparation: KAP.

Tutorial is loading...

Problem author: KAP, preparation: demon1999.

Tutorial is loading...

Problem author: ZhNV, preparation: ZhNV.

Tutorial is loading...

Problem author: SYury, preparation: kuzmichev_dima.

Tutorial is loading...

After waiting for a long time,the tutorial is finally ready.

Cwas quite hard to understand, time zones are really confusing mind :Dthanks for cool task )

Can someone please explain it again, thanks.

Let's find out which timezones will participate when the local time in TZ#1 is 1 hour. s =minimum time of start f =maximum time of finish => f-1=maximum time of start.

If time is 1 in first time zone then in the second time zone is two, in the third is 3...

Okey, let's make it on a sample:

5

1 1 1 1 1

2 4

Which time zones will participate? TZ#2 and TZ#3. TZ#4 won't participate because their local time will be 4. So the contest will end at 5, which is not good for us.

Now let's find out: "How many people will be in?" Answer is obvious a[2]+a[3], which is a[s]+a[s+1]...+a[f-1].

Now let's find which timezones will participate on h=1...n; (h=local time at TZ#1)

Let's make it again on sample:

5

1 1 1 1 1

2 4

h=1: a[2]+a[3]

h=2: a[1]+a[2]

h=3: a[5]+a[1]

h=4: a[4]+a[5]

h=5: a[3]+a[4]

More formally for (h=1 to n ) {

beg=s-(h+1)

if (beg<1) beg=n+beg;

end=f-h;

if (end<1) end=n+end;

curans=sum(beg->end)

if (curans>ans)

{

ans=curans;

time=h; }

} This is an O(n*(f-s)) solution. Because each time we calculate sum from the beginning. But we don't need to calculate each that way. We can save previous sum. And the current sum will be:

cursum=(previoussum+a[begin])-a[end%n+1];

Complexity O(n)Thanks!

Can someone explain problem C with example given in the problem.

Using lemmas 1 and 3 from

Eeditorial it is easy to prove that we can useternarysearch as alternative way to find optimal prefix for each query withtype= 2.Can you please explain the ternary search idea ? At first glance on this problem I thought a ternary search idea but while implementing it, I found some difficulties. Then I solved it using binary search. Thanks in advance.

Well, let store all

xinx[i], and while addingielement we will calculate prefix sum for firstielemets (sum[i] =sum[i- 1] +x[i]).Then, it is obvious that we should always use

x[1] andx[cnt] element (wherecnt— how many elements we have at the moment). So, we takex[cnt] and then search best answer choosing what prefix should we use from [1;cnt- 1].Define

get(i) as function returnsmax(i) -mean(i) (what we want to maximize).max(i) =x[cnt] for anyi,mean(i) = (sum[i] +x[cnt]) / (i+ 1).Suppose we have best answer with

i=p. Then,get(i- 1) ≤get(i) for anyiin range [1;p], andget(i) ≥get(i+ 1) for anyiin range [p;cnt- 1].We can use it to search

pin [1;cnt- 1] with ternary search (and answer for query will beget(p)): http://codeforces.com/contest/939/submission/35440173I would like to share What I learnt from question E.

Solution with multiSet, O(n*log n) in worst case scenario, uses long double , gets TLE , 3 seconds

Solution with Queue, O(n) in worst case scenario, uses long double, gets TLE , 3 seconds

Solution with Queue, O(n) in worst case , uses Long long instead Long double, Gets

Accepted, 608 mili secondsSolution with multiset, O(n*log n) in worst case, uses long long instead of long double , gets

Accepted, 654 mili secondsConclusion :

1)

O(N) solution with 'long double' data type is slower than O(N*log N) solution with 'long long' data type. type.(still runtime depends on how many operations we are doing in each cycle)2)Question E is pretty straight forward, There was no need for Binary Search or Ternary Search.

3)Always prefer to use "long long" or "int" , instead of "double" or "long double". Because simple operations like Addition or subtraction becomes very slow on these data types.

GL & HF :) .

Q·log_{1.5}Qsolution with long long got accepted in 951 msyeah, but still better than using Long double :D .

I can't understand problem C, In example 1 it is said that contest should start at 3 hours at time zone 1 that would be 1 hour in time zone 2 and 2 hour in time zone 3. But As stated by problem time at ith time zone should be i if time at 1 is 1 hour. So the time at second time zone should be 4 hours and third 5 hours.

hmm, you should imagine that like in real life, except it only has n hours ( not 24 hours) and doesn't have 0 hours. Here is an example how that goes in time zone 1 if we have n=4: TZ1: 1 2 3 4 | 1 2 3 4 | 1 2.. and so on. Meanwhile, in TZ2: 2 3 4 | 1 2 3 4 | 1.. and so on . Hope you can understand, my English and explanations is not good at all =))) .

I got it, thanks.

Shouldn't in Task E, Lemma 3 should say

f(i) is non-increasing?Anyone please explain or share the solution idea of problem F — Cutlet. I think another editorial is needed for understanding the given editorial for this problem.

I'm not sure what the editorial is saying either, but let me explain my solution.

Let the two sides of the cutlet be A and B. Consider the case where we have two availability intervals [

l_{i},r_{i}] and [l_{j},r_{j}] withi<j. Let's say we enter interval i with side A, flip to B during interval i, stay at side B until interval j, and flip to A during interval j. If we only consider these two flips, then the amount of time we had side B would be in the interval [l_{j}-r_{i},r_{j}-l_{i}]. If we have two more intervals x,y wherei<j<x<y, we can perform the same flip as above between i and j with x and y as well (ie. A -> flip at x -> B -> flip at y -> A). In fact there are no conflicts regardless of how we flip things at i, j, x, and y as long as they are of the form I described earlier.Let's build a graph as follows. Each interval becomes a vertex. Let

i<j, we connect interval i to j with a directed edge of length 1 and value [l_{j}-r_{i},r_{j}-l_{i}]. Connect the source to all intervals with value [l_{i},r_{i}], and connect all intervals to the sink with value [2n-r_{i}, 2n-l_{i}]. These edges represent the time the cutlet spends at side B. We also have to add the side A edges, which are just duplicates of these with value [0,0]. Value here means the time the cutlet spends on side B.Now, taking an edge from i to j means we do the flips A -> flip at i -> B -> flip at j -> A. This gives some time in the value of the edge. The value of a path whose edges have values [

l_{1},r_{1}], [l_{2},r_{2}], ... is simply [l_{1}+l_{2}+ ...,r_{1}+r_{2}+ ...].IF we add the restriction that we can only have The solution to the problem is now finding the shortest path from the source to the sink whose value contains

n, taking alternating side A and side B edges (ie. we can have the cutlet on side B for timen).To deal with the case where we might have to flip multiple times in one interval, first we note that we want to flip at most twice in a given interval. So we add side B edges from i to i with value [0,

r_{i}-l_{i}]. This doesn't cause a problem because we must take alternating side A and B edges. However, this only considers cases where we do A -> flip at i -> B -> flip at i -> A, but this is sufficient because the B -> flip at i -> A -> flip at i -> B case cancels out with this one.To find the shortest alternating path, you can use Dijkstra with an extra flag that says whether to take a side A edge or a side B edge. Also store the value for each visit. Whenever we reach the sink, check to see if the value contains

n, if it does, then we found the answer, otherwise, skip this path and keep looking.Can some one explain the E problem in a more detailed way?

How to solve D if we can apply spells only on first string?

Applying spells only on first string is equivalent to applying spells on either strings since spells are bidirectional in this case.

What I meantInput2

ab

ba

Output2

a b

b a

In that case output will be the number of positions where S1[i]!=S2[i].

Why has C been tagged as two pointers and binary search? Isn't it misleading, when you just have to use the prefix sum?

For problem E Lemma 3: It should be f(i) is non-increasing for increasing i, for M(i) to have a maxima. If f(i) = M(i + 1) — M(i) is decreasing or non-increasing it implies M(i) has a minima. In the proof statement -

f(i + 1) - f(i) ≤ 0, this means that f(i) does not decrease when i increasesis simply wrong. It means f(i) does not increase.