Infoleague Winter 2022 Round 1 Div. 2 Editorial

Revision en1, by Gheal, 2022-01-08 16:46:10

103503A — Make Sum Great Again

Hint 1
Hint 2
Hint 3
Hint 4

\item Solution: \end{itemize} \textbf{Lemma:} The number of operations will never exceed $$$\sqrt{2 \cdot s}$$$.

Since we need to maximize the final length of the array, it is always optimal to add the smallest integer which is not already present in $$$a$$$.

The naive implementation of this idea has a runtime complexity of $$$O(n \cdot \sqrt s)$$$, although this can be easily optimized to $$$O((n+ \sqrt s)log(n))$$$, if binary search is used to check whether the new elements are already present in $$$a$$$.

The optimal solution has a runtime complexity of $$$O(N log S)$$$. Based on hints $$$3$$$ and $$$4$$$, we can find the value of $$$x$$$ with binary search. For some $$$x$$$, the sum of the elements in $$$a$$$ will be equal to $$$sum(x)=\frac{x\cdot(x+1)}{2}+\sum_1 v_i$$$, where $$$\sum_1 v_i$$$ is the sum of the elements greater than $$$x$$$.

Since the sum of elements $$$sum(x)$$$ is a monotonous function, we can use binary search on the interval $$$[1,\sqrt{2 \cdot s}]$$$ to find the exact value of $$$x$$$.

Final time complexity: $$$O(N log S)$$$

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en20 English Gheal 2022-01-08 21:32:38 152
en19 English Gheal 2022-01-08 21:02:08 0 (published)
en18 English Gheal 2022-01-08 20:53:28 372
en17 English Gheal 2022-01-08 17:36:05 134
en16 English Gheal 2022-01-08 17:26:10 4809
en15 English Gheal 2022-01-08 17:24:06 1808
en14 English Gheal 2022-01-08 17:22:43 708
en13 English Gheal 2022-01-08 17:20:14 820 Tiny change: 'eq 0$;\n- \neq k$.\' -> 'eq 0$;\n- $a_i \neq k$.\'
en12 English Gheal 2022-01-08 17:02:26 5 Tiny change: 'eq 0$;\n- \neq k$.\' -> 'eq 0$;\n- $a_i \neq k$.\'
en11 English Gheal 2022-01-08 17:02:02 56
en10 English Gheal 2022-01-08 17:01:18 5
en9 English Gheal 2022-01-08 17:00:59 1438 Tiny change: '="Solution>\n\nTo be' -> '="Solution">\n\nTo be'
en8 English Gheal 2022-01-08 16:57:22 6 Tiny change: '="Solution>\n\nTo be' -> '="Solution">\n\nTo be'
en7 English Gheal 2022-01-08 16:56:32 2 Tiny change: '="Solution>\n\nTo be' -> '="Solution">\n\nTo be'
en6 English Gheal 2022-01-08 16:56:14 51
en5 English Gheal 2022-01-08 16:55:40 122
en4 English Gheal 2022-01-08 16:52:11 2248 Tiny change: 'tion">\n\n\textbf{Lemma:} The numbe' -> 'tion">\n\n**Lemma:** The numbe'
en3 English Gheal 2022-01-08 16:47:07 13 Tiny change: 'tion">\n\n\textbf{Lemma:} The numbe' -> 'tion">\n\n**Lemma:** The numbe'
en2 English Gheal 2022-01-08 16:46:52 797
en1 English Gheal 2022-01-08 16:46:10 1652 Initial revision (saved to drafts)