## A. Watermelon

Only if*w*can be presented as 2

*m*+ 2

*k*watermelon can be divided to two even parts.

So

*w*= 2(

*m*+

*k*), where

*m*,

*k*≥

**1**, that is

(

*w*≥

**4**и

*w*- even) - necessary and sufficient condition for watermelon dividing.

## B. Before an Exam

Problem restrictions allow one to use algo complicated as much as he wants. In my opinion the most simple way is written below.- Fill studying time for each day
*sсhedule*with_{i}*minTime*_{i}- Peter wants to study as less as he can - Compute rest:
*need*=*sumTime*- Σ*sсhedule*. if_{i}*need*< 0 than Peter can't satisfy lower bound of parents restrictions in schedule making: even if schedule is as small as possible he will go over the quota. - In each day Peter has free studying hours: Δ = min(
*need*,*maxTime*-_{i}*sсhedule*) - each day_{i}*i*Peter can additionally study. (With each day*sсhedule*increase on Δ and_{i}*need*decrease on Δ). - if
*need*> 0 than Peter can't satisfy lower bound: studying with max power he has no time.

*sсhedule*

*- is correct Peter's schedule if 2 and 4 not fulfilled.*

_{i}## C. Registration system

First, one can see the restrictions ≤ 10^{5}, that is he can expect n*log(n) solution.

Next, each string consist of "all lowercase Latin letters", that is it doesn't contains digits.

Because of it for each string we can compute what time we see it in the input. One needs to write "OK" for first request of current string, otherwise <

*string*><

*computed number*>.

This numbers can be computed by associate array (map in C++) or simple by sorting array of:

(

*string*,

*number in input file*),

sorted array would be splitted to blocks with equal strings. In each block one can set numbers from 1 to

*block_size*.

## D. Mysterious Present

Problem can be solved by dynamic programming approach for O(n^{2}) by time and O(n) by memory.

- Sort all envelopes by pairs (
*w*,_{i}*h*) or by product_{i}*w**_{i}*h*in nondecreasing order. Because of it envelope_{i }*i*can be put in envelope*j*only if*i*<*j*. That is for any chain {*a*_{1},*a*_{2}, ...,*a*_{n}} is true that*a*_{1 < }*a*_{2 < ... < }*a*_{n}. - Just delete all envelopes in which card can't be put in.
- Add to sorted envelopes array
*a*_{0}- Peter's card. - Introduce DP function:
*dp*[*i*] maximum chain length which ends in*i*-th envelope._{} *dp*[0] = 0,*dp*[*i*] = max(*dp*[*j*]) + 1, where*i*≥ 1, 0 ≤*j*<*i*and*j**can be put in**i*. This function can be easily got by previously computed values of it.

*dp*[

*i*]), where 0 ≤

*i*≤

*n*.

For each

*dp*[

*i*] one can remember index

*p*[

*i*] =

*j*with which maximum reached in formula p5. If one knows

*s*- envelope index in which maximal chain ends he can restore all answer sequence (

*i*

_{0}=

*s*,

*i*

_{k+1 }=

*p*[

*i*]).

_{k}
initializeall chains(exact n pieces) withdp[i] =1(1 ≤i≤n), it would be done automatically by formula p5.2. Simultaneously we will get that

all chainswillstart inPeter'sletter.PS: In my solution from the contest I was creating chains from big envelopes to small (in decreasing order) and I add fake envelope with (w

_{0}, h_{0)}= (+inf, +inf),dp[0] = 0. Because of I didn't catch that letter itself is better candidate to chain origin. And next I was choosing between chain ends in which card can be put in.beta #4can be discussed with me). I think posting code on forum is wrong way and you can usepersonal messages.Second way - you can write to organizers and

ask specific teston specific task. But do not abuse with it. This is the last that you need to do.Can problem C be solved using binary search? We at first sort the strings and find the specific name using binary search.

I guess using std::map is effectively doing the same thing, implementing via BST.

Hence, 1st tier of argument is about std::map over linear, then lastly std::unordered_map over std::map

excuse me, could you please explain the complexity of your solution for problem D? And why should we sort the envelopes by product wi*hi?

1) One could compute max in any range of «dp» array in O(n) complexity. One must compute all dp[i] = max(dp[j]) + 1 in range [0, j) to get length of the longest sequence. Thus we get O(n²) complexity in my solution.

2) To solve problem by my solution one must sort envelopes in such a way that

if W[i] < W[j] and H[i] < H[j] than i < jSo it could be stated that

if in pair of envelopes one envelope could be put to another thanlesser envelope should has lesser area and vice versa.3) This is classical problem: find longest increasing subsequence. Unfortunately, I can't give you links to english sources. I have this one e-maxx.ru/algo/longest_increasing_subseq_log.

I hope it helps!

thanks you

I solved D with an O(n²) memory approach using short int lol