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.

Already tried... Here is my submission.

~~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.I am not able to understand in problem C Anagram Search that while moving to next substring why we are doing this in

b[s[n + 1] - 'a' + 1]+ +in the editorialWhy are we doing this — 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 ?

Because when this situation occurs, then while moving maximum-height soldier to the start of the line by swapping we also move minimum-height soldier one step towards the end of the line. But this step is already counted by the formula given in the problem editorial, so we have to subtract one.

Is there any proof of the solution to problem d?

Can anyone please find the bug in my code for problem A. It outputs 11 for 7 10 10 58 31 63 40 76 whereas the correct answer is 10 ~~~~~ Your code here... ~~~~~

## include<bits/stdc++.h>

using namespace std; int main() { int n; cin >> n; vector v(n); for(int i = 0; i < n; i++) { cin >> v[i]; }

int maxele = INT_MIN; int minele = INT_MAX; for(int i = 0; i < n; i++) { maxele = max(maxele, v[i]); minele = min(minele, v[i]); }

int maxelepos; int minelepos; for(int i = 0; i < n; i++) { if(v[i] == maxele) maxelepos = i; } for(int i = n — 1; i >= 0; i--) { if(v[i] == minele) minelepos = i; }

int res = 0;; if(maxelepos < minelepos) { res = maxelepos + ((n — 1) — minelepos); } if(maxelepos == minelepos) { ; } if(maxelepos > minelepos) { maxelepos--; res = maxelepos + ((n — 1) — minelepos); }

cout << res; return 0; } ~~~~~

if the leftmost soldier with the maximum height is more right then the rightmost soldier with the minimum height why we have to subtract one from the answer ???

Take the case of the example 10,10,58,37,63,40,76. Here 76 is the leftmost element with maximum height and 10 at position 2 is the right most element with minimum height. So the number of swaps required to move 76 to position 1 is 7-1=6 and the number of swaps required to move 10 to position 7 is 7-2 = 5. But suppose we initially start swapping 76 to the end, then at a certain position 76 gets swapped with our 10 which moves by one place forward, more close to the end, so the number of swaps required while swapping the rightmost minimum element will be one less. so answer = 6 + 5-1=10.

Can anyone send me some more test cases for D?