313A - Ilya and Bank Account
This problem is the easiest one. You need to use only div and mod functions. If n>0, then answer is n, else you need to delete one of two digits.
For better understanding you can look at solution.
313B - Ilya and Queries
Precalculate some array Ai, that Ai = 1, if si = si + 1, else Ai = 0. Now for any query (l, r), you need to find sum of Ai, that (l ≤ i < r). It is standart problem. For solving this problem you can precalcutate some another array Sum, where Sumi = A1 + A2 + ... + Ai. Then sum of interval (l, r) is Sum_r — Sum_{l-1}.
For better understanding you can look at solution.
313C - Ilya and Matrix
At the start sort array. Let Ci — number of times of entering the number in Aі optimal placement. Answer is sum of Ai * Ci for all i (1 ≤ i ≤ 4n). If we look at the array C, we can see that for maximal element C = n + 1 (for array with size 4n), then for second, third and fourth maximum elements C = n. On this basis we can see, that for array with non-increasing order answer calculate like Sum(1, 1) + Sum(1, 4) + Sum(1, 16) + ... + Sum(1, 4n). So, for solve this problem you have to know only sort.
For better understanding you can look at solution
313D - Ilya and Roads
To solve this problem you need to use dynamic programming. Let Fulli, j — minimal cost of covering interval (i, j). Fix left border and move right. You can solve this subtask with complexity O(nm) or O(nmlogn). Now we need to solve the standart problem of dynamic programming. Cover K points with intervals that have not intersect. This problem with square dynamic. dpi, j — minimal cost of covering j-points, if you look some prefix length i. Answer for all problem is minimal integer from dpi, j, (k ≤ j ≤ n).
To solve second part:
1) dpi + 1, j = min(dpi + 1, j, dpi, j) — skip point with number i + 1
2) dpk, j + len = min(dpk, j + len, dpi, j + Cost); Cost — cost of interval with length len, that ending at point k. We precalculate Cost at first part of solution.
For better understanding you can look at solution
313E - Ilya and Two Numbers
Author solution is harder than that which is offered by MrDindows. It is solution of MrDindows.
1) Get the number of our sequences in sorted by frequencies. Thus from the first sequence (hereinafter — the first type) — in a direct order from the second — to the contrary.
2) These numbers are put on the stack, where if, recording onto the stack of the second type, we find the number at the top of the first type, then this pair of extract and add to the answer.
3) At the end, obviously the stack we can find a number of properties of the second type and the first bottom — on. Then their grouping in response pairs with the start and end.
For better understanding you can look at solution.
Sorry for waiting.