Problem A

It's clear that the leftmost soldier with the maximum height should be the first and the rightmost soldier with the minimum height should be the last. Thus we will minimize the number of swaps. And the answer is number of leftmost soldier with the maximum height - 1 +

*n*- number of rightmost soldier with the minimum height. And if the leftmost soldier with the maximum height is more right then the rightmost soldier with the minimum height we should subtract one from the answer.Problem B

Let's try to check all integer points of the table perimeter and add to the answer such of them that don't cover by circles of radiators. Let

*x*_{a}<*x*_{b}and*y*_{a}<*y*_{b}, and if it's not true then swap*x*_{a}and*x*_{b},*y*_{a}and*y*_{b}. So generals sit in the next integer points: (*x*_{a},*y*), (*x*_{b},*y*), (*x*,*y*_{a}), (*x*,*y*_{b}), where*x*_{a}≤*x*≤*x*_{b}и*y*_{a}≤*y*≤*y*_{b}. We should be attentive when we count the generals who sits in points: (*x*_{a},*y*_{a}), (*x*_{a},*y*_{b}), (*x*_{b},*y*_{a}), (*x*_{b},*y*_{b}), that don't count them twice.Problem C

Let's count number of each letter in the second string and save it, for example, in array

*a*[1..26]. For the first strings' prefix of length*n*, where*n*is the length of second string, (it's the first substring) we count number of each letter in array*b*[1..26]. We don't count characters ``\texttt{?}''. If there are*b*[*i*] ≤*a*[*i*] for all*i*, then it's good substring. Then go to the second substring: subtract from the array*b*the first character:*b*[*s*[1] - '*a*' + 1] – and add*n*+ 1 character:*b*[*s*[*n*+ 1] - '*a*' + 1] + + . If some of these characters is ``\texttt{?}'' then we shouldn't do for it the subtraction or addition. Then repeat the showed check and go to the next substring. Let's repeat this procedure for all substrings of length*n*.Problem D

*d*[

*i*] --- the minimum distance from vertex

*s*to vertex

*i*, that counted by algorithm of Dijkstra. "et's count the number of points on each edge of the graph that are on the distance

*l*form the vertex

*s*(and

*l*--- the minimum distance from these points to

*s*).

For edge (u, v):

if

*d*[*u*] <*l*and*l*-*d*[*u*] <*w*(*u*,*v*) and*w*(*u*,*v*) - (*l*-*d*[*u*]) +*d*[*v*] >*l*then add to the answer the point on this edge, the distance of which to the vertex*u*is*l*-*d*[*u*];if

*d*[*v*] <*l*and*l*-*d*[*v*] <*w*(*u*,*v*) and*w*(*u*,*v*) - (*l*-*d*[*v*]) +*d*[*u*] >*l*then add to the answer the point on this edge, the distance of which to the vertex*v*is*l*-*d*[*v*];if

*d*[*v*] <*l*and*d*[*u*] <*l*and*d*[*u*] +*d*[*v*] +*w*(*u*,*v*) = 2 **l*then add to the answer the point on this edge, the distance of which to the vertex*v*is*l*-*d*[*v*] and to the vertex*u*is*l*-*d*[*u*].And if

*d*[*i*] =*l*, then let's add to the answer this point.Problem E

It's clear that the nearest squares of the secondary diagonal to some sportsman form the "segment" of the squares of the secondary diagonal. Let's write these segments for each sportsman.

Let's consider sportsmen so that we should compare to each sportsman excactly one square of the secondary diagonal from his "segment" and to each square of the secondary diagonal no more then one sportsman. It's clear that sportsmen can reach theirs squares without occupying the same square simultaneously with another sportsman. We should maximize the number of choosen sportsmen. And solution of this reformulated problem is greedy.

After sorting the left endpoints of the segments, you loop through them, and use a priority queue (heap data structure) to repeatedly select the next non-intersecting segment with the leftmost possible right endpoint.

By the way, the editorial's question marks are not displaying properly.

Thanks a lot.

Very sad that its impossible to get Accepted on problem B with Ruby.

~~Can somebody help me with this (code) problem (C) ?~~stringThe firstline isnon-emptys, consisting of no more than 10^{5}lowercase Latin letters and characters "?".stringThe secondline isnon-emptyp, consisting of no more than 10^{5}lowercase Latin letters.remains.Are you talking about the cases that only have one line?

I think maybe because the string in the first line is so long that the system can only show a small prefix of it. then

the whole input file remainedis ignored.eg.

xxxxxxxxxxxxxxxxxx

yyyyyyyyyyyyyyyyyy

zzzzzzzzzzzzzzzzzz

aaaaaaaaaaaaaaaaaa

bbbbbbbbbbbbbbbbbb

will looks like

xxxxxxx...

In Codeforces, large test case displays first 256 characters only, after which they show ellipsis (...)

Thank you,after 5 years SyFy can at last live happily.

O(V×logE) using data structures to extract minimum inO(logn), for example, prority queue based on either binary heap or sorted set.can someone explain the question i didn't get it?!

I have done the same approach in problem A but not getting the right answer

import java.util.Scanner;

/** * A144 */ public class A144 {

}

can anyone please say where i am making mistake[problem:144A]

I think you need to run both the conditions inside the for loop....remove the "else" keyword and try.

PROBLEM AI don't understand, what my mistake is, i'm getting wrong Answer on test case 4, everytime! I implemented everything according to the Tutorial only.Can Any1 help me?

Well, good job! you almost got it. Now, what did you miss? as we iterate through the array we need to get the first occurance of the max height and the last occurance of the min height. This is to decrease the time required to place the soldiers in their respective positions. Here's the accepted code:

Thank You! That was impressive! I really did forget about that case!

Hi, I just started j hope this isn’t a stupid question but any idea my code doesn’t work?