Codeforces Round #695 (Div. 2) My Editorial

Revision en1, by three_nil, 2021-01-09 12:46:29

A

hint

Try making solution of n=4 or n=5

solution

Handle n=1 ,n=2 and n=3 case separately Now n>=4 the answer will always have 9 in first position.Solution depends only on the first position at which we stopped.Suppose we stop at position p>=3.

If 1st position is stopped at time t1, then second position must have stopped at time t2=t1-1, third at t3 = t2-1 = t1-2 Since first position have 9 and second is stopped at a second earlier second position is 8 and similarly third position is 7.

If u have tried building solution for n=4 you must have observed that it is possible to 989 in first three positions respectively which better solution than the one we tried to construct above. Thus stopping at 2nd position when it shows 8 is optimal solution.

To construct rest of the string s[I]=(s[I-1]+1)%10

C

hint

We are first trying to create a max negative value which we will then in final step subtract from a positive value

solution

Suppose the bags are A1,a2,a3……an1
B1,b2,b3…..Bn2
C1,c2,c3……cn3
Let sum=a1+a2+a3….An1+b1+b2+b3….Bn2+c1+c2+c3….Cn3
We can have mainly have two type of final values
First We can subtract values b2,b3,b4…..Bn2, c1,c2,c3……cn3 from an1 The value of a1 would then be a1-b2-b3-b4…..Bn2-c1-c2-c3…..-cn3 And then finally subtract a1,a2,a3…..An1 from b1 The value of b1 would then be B1-(a1-b2-b3-b4…..Bn2-c1-c2-c3…..-cn3)-a2-a3-a4…an1 =b1+b2+b3….Bn1+c1+c2+c3…..+cn3-a1-a2-a3-a4…an1 =sum-2*(a1+a2+a3….An1)

Second Another answer that we can construct is Subtract values b2,b3,b4…..Bn2, c2,c3……cn3 from an1 note we are not subtracting c1 The value of a1 will be a1-b2-b3-b4…..Bn2-c2-c3…..-cn3 Subtract values a2,a3…..An1 from bn1 The value of c1 will be c1-a2-a3-a4…..An1 And then finally subtract a1 and c1 from b1 The final value would then be B1-(a1-b2-b3-b4…..Bn2-c2-c3…..-cn3)-(c1-a2-a3-a4…..An1) =b1+b2+b3….Bn2+c2+c3+….Cn3+a2+a3+a4…an1-a1-c1 =sum-2*(a1+c1)

Thus the answer=max(sum-2*(a1+a2+a3….An1),sum-2*(a1+c1)) Answer=sum-min(2*(a1+a2+a3….An1),2*(a1+c1)) Ans=sum-2*min((a1+a2+a3….An1),a1+c1) I have considered bags randomly without loss of generality
That mean I want to compare the bag which has minimum and minimum elements of two bags

E Solution Let us see when the answer is definitely 0 Suppose three vertices x,y,z exists such that ax=ay=az and y lies on path from x to z (or z=x since undirected tree both are same) In this scenario the answer is always 0. Suppose the answer is not and we are able to find a distinctive root w Case 1 : w lies between x-y Y lies in path from w to z and ay=az therefore w is not a distinctive root Case 2 : w lies between y-z Y lies in path from w to x and ay=ax therefore w is not a distinctive root Case 3 : w does not lie in path from x to z Subcase a :distance of x from w is less than distance of z from w X and y both lie in path from w to z Subcase b :distance of x from w is less than distance of z from w X and y both lie in path from w to z

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en9 English three_nil 2021-01-11 13:18:03 372 Tiny change: 'c_2,c_3……cn3$ from $a_' -> 'c_2,c_3……c_{n_3}$ from $a_'
en8 English three_nil 2021-01-11 12:56:55 0 Reverted to en5
en7 English three_nil 2021-01-11 12:52:55 20 Reverted to en5
en6 English three_nil 2021-01-09 16:34:30 20 Tiny change: 'n\n\n\nE\n### Solu' -> 'n\n\n\nE\n==================\n### Solu'
en5 English three_nil 2021-01-09 13:56:34 0 (published)
en4 English three_nil 2021-01-09 13:55:57 231
en3 English three_nil 2021-01-09 13:51:40 1182 Tiny change: '0e565.png)\nTry gett' -> '0e565.png)<br>\nTry gett'
en2 English three_nil 2021-01-09 13:12:51 1655 Tiny change: 'lues<br>\n**First*' -> 'lues<br>\n\n**First*'
en1 English three_nil 2021-01-09 12:46:29 3139 Initial revision (saved to drafts)