id
stringlengths
3
8
aliases
listlengths
1
19
contest_id
stringlengths
1
4
contest_name
stringlengths
10
125
contest_type
stringclasses
3 values
contest_start
int64
1.27B
1.72B
contest_start_year
int64
2.01k
2.02k
index
stringclasses
58 values
time_limit
float64
0.4
60
memory_limit
float64
4
1.02k
title
stringlengths
2
64
instruction_seed
stringlengths
1
9.88k
input_format
stringlengths
1
2.72k
output_format
stringlengths
1
2.22k
interaction_format
stringclasses
118 values
note
stringlengths
13
5.36k
examples
listlengths
0
7
editorial
stringlengths
11
22.2k
embedding
listlengths
3.07k
3.07k
1615/H
null
1615
Codeforces Global Round 18
CF
1,640,356,500
2,021
H
2
256
Reindeer Games
There are $$$n$$$ reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingly, the "Top Reindeer" title is just a measure of upvotes and has nothing to do with their skill level in the rein...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le 1000$$$; $$$1\le m\le 1000$$$) — the number of reindeer and requirements, respectively. The second line contains $$$n$$$ integers $$$a_1,\ldots, a_n$$$ ($$$1\le a_i\le 10^9$$$), where $$$a_i$$$ is the current score of reindeer $$$i$$$. The next $$...
Print $$$n$$$ integers $$$b_1,\ldots, b_n$$$ ($$$-10^{15}\le b_i\le 10^{15}$$$), where $$$b_i$$$ is the score of the $$$i$$$-th reindeer after all operations. If there are multiple solutions achieving the minimum number of operations, you may output any. We can prove that there is always an optimal solution such that...
null
null
[ { "input": "7 6\n3 1 4 9 2 5 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7", "output": "1 1 4 4 4 5 6" }, { "input": "4 6\n6 5 8 2\n3 1\n4 1\n3 2\n1 2\n2 3\n3 1", "output": "6 6 6 2" }, { "input": "10 18\n214 204 195 182 180 176 176 172 169 167\n1 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2\n6 1\n6 2\n...
Let's try to find a nice lower bound for the answer. Let's denote a requirement of two nodes $$$u$$$ and $$$v$$$ by a directed edge $$$u\to v$$$. We can observe that if there are two nodes $$$u$$$ and $$$v$$$ such that there's a requirement $$$u\to v$$$ (or a path of requirements from $$$u$$$ to $$$v$$$), then we will ...
[ 0.014394356869161129, -0.017048444598913193, -0.007996113039553165, 0.030657408758997917, 0.019174421206116676, -0.008957542479038239, -0.03759053349494934, 0.013852707110345364, 0.007698205299675465, 0.055410828441381454, 0.02302013896405697, 0.0029807693790644407, -0.020785830914974213, ...
137/A
null
137
Codeforces Beta Round 98 (Div. 2)
CF
1,324,015,200
2,011
A
2
256
Postcards and photos
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not ...
The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the i-th character in the string is the letter "С", that means that the i-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the ...
Print the only number — the minimum number of times Polycarpus has to visit the closet.
null
In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both time...
[ { "input": "CPCPCPC", "output": "7" }, { "input": "CCCCCCPPPPPP", "output": "4" }, { "input": "CCCCCCPPCPPPPPPPPPP", "output": "6" }, { "input": "CCCCCCCCCC", "output": "2" } ]
null
[ -0.02251593954861164, 0.01709514483809471, -0.012404979206621647, 0.007058817893266678, -0.011320820078253746, -0.037647027522325516, 0.01604241132736206, 0.03877832368016243, -0.0019561999943107367, 0.03598150983452797, -0.0018246081890538335, 0.014494734816253185, -0.024055760353803635, ...
137/B
null
137
Codeforces Beta Round 98 (Div. 2)
CF
1,324,015,200
2,011
B
2
256
Permutation
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of n integers is calle...
The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).
Print the only number — the minimum number of changes needed to get the permutation.
null
The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with...
[ { "input": "3\n3 1 2", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "2" } ]
null
[ -0.004783516749739647, -0.008257793262600899, 0.0034806630574166775, 0.02571220137178898, 0.013705509714782238, 0.03400192782282829, -0.01940230280160904, 0.023834558203816414, 0.020858433097600937, 0.009298798628151417, -0.007204014807939529, -0.029275888577103615, -0.02449875883758068, 0...
137/C
null
137
Codeforces Beta Round 98 (Div. 2)
CF
1,324,015,200
2,011
C
2
256
History
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the Wo...
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in ...
Print the only integer — the answer to the problem.
null
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" } ]
null
[ 0.01831849291920662, -0.019038433209061623, -0.012622960843145847, 0.032621316611766815, 0.009359229356050491, 0.006939428858458996, 0.011047090403735638, 0.019006434828042984, 0.014030844904482365, 0.048667993396520615, -0.008527298457920551, -0.018334491178393364, -0.020526310428977013, ...
137/D
null
137
Codeforces Beta Round 98 (Div. 2)
CF
1,324,015,200
2,011
D
2
256
Palindromes
Friday is Polycarpus' favourite day of the week. Not because it is followed by the weekend, but because the lessons on Friday are 2 IT lessons, 2 math lessons and 2 literature lessons. Of course, Polycarpus has prepared to all of them, unlike his buddy Innocentius. Innocentius spent all evening playing his favourite ga...
The first input line contains a non-empty string s which is the text of "Storm and Calm" (without spaces). The length of the string s does not exceed 500 characters. String s consists of uppercase and lowercase Latin letters. The second line contains a single number k (1 ≤ k ≤ |s|, where |s| represents the length of th...
Print on the first line the minimum number of changes that Innocentius will have to make. Print on the second line the string consisting of no more than k palindromes. Each palindrome should be non-empty and consist of uppercase and lowercase Latin letters. Use the character "+" (ASCII-code 43) to separate consecutive ...
null
null
[ { "input": "abacaba\n1", "output": "0\nabacaba" }, { "input": "abdcaba\n2", "output": "1\nabdcdba" }, { "input": "abdcaba\n5", "output": "0\na+b+d+c+aba" }, { "input": "abacababababbcbabcd\n3", "output": "1\nabacaba+babab+bcbabcb" } ]
null
[ 0.01699342392385006, -0.007231963332742453, -0.00842165295034647, 0.015522263012826443, 0.005411775317043066, 0.0064888764172792435, -0.017353709787130356, -0.0036309934221208096, -0.022187527269124985, 0.030414026230573654, 0.017578886821866035, 0.0002627075300551951, -0.0508001334965229, ...
137/E
null
137
Codeforces Beta Round 98 (Div. 2)
CF
1,324,015,200
2,011
E
2
256
Last Chance
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Inn...
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes. Two substrings are considered different if their positions of occurrence are different. So if some string o...
null
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length. In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
[ { "input": "Abo", "output": "3 1" }, { "input": "OEIS", "output": "3 1" }, { "input": "auBAAbeelii", "output": "9 3" }, { "input": "AaaBRAaaCAaaDAaaBRAaa", "output": "18 4" }, { "input": "EA", "output": "No solution" } ]
null
[ 0.044933341443538666, 0.008405262604355812, -0.0049634831957519054, 0.003574569243937731, 0.011664005927741528, -0.021088523790240288, 0.00882157776504755, 0.0069230361841619015, -0.01778671145439148, 0.0312667153775692, -0.02295476384460926, 0.019265349954366684, -0.04306710138916969, 0.0...
1771/A
null
1771
Codeforces Round 837 (Div. 2)
CF
1,670,772,900
2,022
A
2
256
Hossam and Combinatorics
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem. Now, they have an array $$$a$$$ of $$$n$$$ positive integers, Hossam will choose a number $$$a_i$$$ and Hazem will choose a number $$$a_j$$$. Count the number of interesting pairs $$$(a_i, a_j)$$$ that meet all the following con...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$), which denotes the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case c...
For each test case print an integer — the number of interesting pairs $$$(a_i, a_j)$$$.
null
In the first example, the two ways are: - Hossam chooses the fourth number $$$8$$$ and Hazem chooses the fifth number $$$1$$$. - Hossam chooses the fifth number $$$1$$$ and Hazem chooses the fourth number $$$8$$$. In the second example, the four ways are: - Hossam chooses the second number $$$2$$$ and Hazem chooses ...
[ { "input": "2\n5\n6 2 3 8 1\n6\n7 2 8 3 2 10", "output": "2\n4" } ]
Firstly, let's find $$$\max_{1 \le p, q \le n} |a_p - a_q| = max(a) - min(a)$$$ if it's equal to zero, then any pair is valid, so answer if $$$n \cdot (n - 1)$$$ Otherwise, let's calculate $$$count\_min$$$ and $$$count\_max$$$. Answer is $$$2 \cdot count\_min \cdot count\_max$$$
[ -0.02992023341357708, -0.007699362467974424, -0.0030643343925476074, 0.017141306772828102, 0.02356633171439171, -0.004015641286969185, 0.011723894625902176, 0.021942295134067535, -0.0016536737093701959, -0.01410660706460476, 0.015647664666175842, -0.020590905100107193, 0.002191562205553055, ...
1771/C
null
1771
Codeforces Round 837 (Div. 2)
CF
1,670,772,900
2,022
C
3
256
Hossam and Trainees
Hossam has $$$n$$$ trainees. He assigned a number $$$a_i$$$ for the $$$i$$$-th trainee. A pair of the $$$i$$$-th and $$$j$$$-th ($$$i \neq j$$$) trainees is called successful if there is an integer $$$x$$$ ($$$x \geq 2$$$), such that $$$x$$$ divides $$$a_i$$$, and $$$x$$$ divides $$$a_j$$$. Hossam wants to know if th...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$), the number of test cases. A description of the test cases follows. The first line of each test case contains an integer number $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case conta...
Print the answer — "YES" (without quotes) if there is a successful pair of trainees and "NO" otherwise. You can print each letter in any case.
null
In the first example, the first trainee and the second trainee make up a successful pair: $$$a_1 = 32, a_2 = 48$$$, you can choose $$$x = 4$$$.
[ { "input": "2\n3\n32 48 7\n3\n14 5 9", "output": "YES\nNO" } ]
If exists $$$x \geq 2$$$ such that $$$a_i$$$ divides $$$x$$$ and $$$a_j$$$ divides $$$x$$$ then exists prime number $$$p$$$ such that $$$a_i$$$ and $$$a_j$$$ divides $$$p$$$. We can choose $$$p = $$$ any prime divisor of $$$x$$$. So, let's factorize all numbers and check, if two of them divides one prime number. We can...
[ -0.011415510438382626, 0.013703572563827038, 0.006002288777381182, 0.012773466296494007, 0.00523030012845993, -0.02862248569726944, 0.046505335718393326, 0.01950743794441223, 0.01669231615960598, 0.029192950576543808, -0.029242556542158127, -0.0076082730665802956, -0.026935890316963196, 0....
1771/D
null
1771
Codeforces Round 837 (Div. 2)
CF
1,670,772,900
2,022
D
1
256
Hossam and (sub-)palindromic tree
Hossam has an unweighted tree $$$G$$$ with letters in vertices. Hossam defines $$$s(v, \, u)$$$ as a string that is obtained by writing down all the letters on the unique simple path from the vertex $$$v$$$ to the vertex $$$u$$$ in the tree $$$G$$$. A string $$$a$$$ is a subsequence of a string $$$s$$$ if $$$a$$$ can...
The first line contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case has one integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^3$$$) — the number of vertices in the graph. The second line contains a string $$$s$$$ of length $$$n$$$, the $$$i$$$-th symbol of ...
For each test case output one integer — the length of the longest maximal sub-palindrome among all $$$s(v, \, u)$$$.
null
In the first example the maximal subpalindromes are "aaa" with letters in vertices $$$1, \, 3, \, 5$$$, or "aca" with letters in vertices $$$1, \, 4, \, 5$$$. The tree from the first example. In the second example there is only one maximal palindrome "bacab" with letters in vertices $$$4, \, 2, \, 1, \, 5, \, 9$$$. ...
[ { "input": "2\n5\nabaca\n1 2\n1 3\n3 4\n4 5\n9\ncaabadedb\n1 2\n2 3\n2 4\n1 5\n5 6\n5 7\n5 8\n8 9", "output": "3\n5" } ]
Let's use dynamic programming method. Let $$$dp_{v, \, u}$$$ as length of the longest maximal sub-palindrome on the path between vertexes $$$v$$$ and $$$u$$$. Then the answer to the problem is $$$\max\limits_{1 \le v, \, u \le n}{dp_{v, \, u}}$$$. Define $$$go_{v, \, u}$$$ $$$(v \neq u)$$$ vertex $$$x$$$ such that it i...
[ 0.00781579315662384, 0.05070115625858307, -0.0032132300548255444, 0.038216184824705124, 0.06760153919458389, 0.007213114760816097, 0.024969937279820442, 0.016024913638830185, -0.040373142808675766, 0.015923410654067993, -0.00785385724157095, 0.017268335446715355, -0.00357483746483922, -0.0...
1771/E
null
1771
Codeforces Round 837 (Div. 2)
CF
1,670,772,900
2,022
E
2
256
Hossam and a Letter
Hossam bought a new piece of ground with length $$$n$$$ and width $$$m$$$, he divided it into an $$$n \cdot m$$$ grid, each cell being of size $$$1\times1$$$. Since Hossam's name starts with the letter 'H', he decided to draw the capital letter 'H' by building walls of size $$$1\times1$$$ on some squares of the ground...
The first line of the input contains two integer numbers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 400$$$). The next $$$n$$$ lines of the input contain $$$m$$$ characters each, describing the grid. The character '.' stands for a perfect square, the character 'm' stands for a medium square, and the character '#' stands for a...
Print a single integer — the maximum number of walls that form a capital letter 'H'. If it is not possible to draw any letter 'H', print $$$0$$$.
null
In the first test case, we can't build the letter 'H'. For the second test case, the figure below represents the grid and some of the valid letters 'H'. Perfect, medium, and bad squares are represented with white, yellow, and black colors respectively.
[ { "input": "2 3\n#m.\n.#.", "output": "0" }, { "input": "7 8\n...#.m..\n..m...m.\n.#..#.m#\n...m..m.\nm.......\n..#.m.mm\n......m.", "output": "16" } ]
Let's preprocess the following data for each cell. 1. first medium cell above current cell. 2. first medium cell below current cell. 3. first bad cell above current cell. 4. first bad cell below current cell. Then we will try to solve the problem for each row (i), and 2 columns (j, k). Now we have a horizontal line in ...
[ 0.003916798159480095, -0.01067751832306385, 0.005428432486951351, 0.0192284993827343, 0.07184106111526489, -0.009031374007463455, 0.03789333999156952, 0.0101458840072155, -0.02267451398074627, 0.0008566994802094996, 0.012925754301249981, -0.00048759812489151955, 0.008787975646555424, 0.014...
1771/F
null
1771
Codeforces Round 837 (Div. 2)
CF
1,670,772,900
2,022
F
1.5
256
Hossam and Range Minimum Query
Hossam gives you a sequence of integers $$$a_1, \, a_2, \, \dots, \, a_n$$$ of length $$$n$$$. Moreover, he will give you $$$q$$$ queries of type $$$(l, \, r)$$$. For each query, consider the elements $$$a_l, \, a_{l + 1}, \, \dots, \, a_r$$$. Hossam wants to know the smallest number in this sequence, such that it occu...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the length of the sequence. The second line contains $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$ ($$$1 \le a_i \le 10^9$$$). The third line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$), the number of q...
For each query, print the smallest number that occurs an odd number of times on the given segment of the sequence. If there is no such number, print $$$0$$$.
null
In the example, $$$$$$l_1 = 1, \, r_1 = 2,$$$$$$ $$$$$$l_2 = 1, \, r_2 = 3,$$$$$$ $$$$$$l_3 = 2, \, r_3 = 4,$$$$$$ $$$$$$l_4 = 1, \, r_4 = 4,$$$$$$ $$$$$$l_5 = 2, \, r_5 = 2,$$$$$$ $$$$$$l_6 = 1, \, r_6 = 5.$$$$$$
[ { "input": "5\n1 2 1 2 2\n6\n1 2\n0 2\n0 6\n0 5\n2 2\n3 7", "output": "1\n2\n1\n0\n2\n2" }, { "input": "10\n51 43 69 48 23 52 48 76 19 55\n10\n1 1\n57 57\n54 62\n20 27\n56 56\n79 69\n16 21\n18 30\n25 25\n62 61", "output": "51\n55\n19\n48\n76\n19\n23\n19\n55\n19" } ]
Note that we were asked to solve the problem in online mode. If this were not the case, then the Mo Algorithm could be used. How to solve this task in online mode? Consider two ways. The first way is as follows. Let's build a persistent bitwise trie $$$T$$$ on a given array, where the $$$i$$$-th version of the trie wil...
[ -0.00797334685921669, 0.005024474114179611, -0.0031181483063846827, 0.026755008846521378, -0.00011865099804708734, -0.0034108206164091825, 0.03412086144089699, 0.026248764246702194, -0.02733718976378441, 0.03318431228399277, -0.007049451116472483, -0.007169684395194054, -0.018174169585108757...
1496/A
null
1496
Codeforces Round 706 (Div. 2)
CF
1,615,377,900
2,021
A
1
256
Split it!
Kawashiro Nitori is a girl who loves competitive programming. One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem. Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{...
For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).
null
In the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$. In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$. In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.
[ { "input": "7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nicpc\n22 0\ndokidokiliteratureclub\n19 8\nimteamshanghaialice\n6 3\naaaaaa", "output": "YES\nNO\nYES\nNO\nYES\nNO\nNO" } ]
If $$$k=0$$$ or $$$s[1,k]+s[n-k+1,n]$$$ is a palindrome, the answer is yes. Otherwise, the answer is no. Note that when $$$2k=n$$$, the answer is no, too. The time complexity is $$$O(n+k)$$$ for each test case.
[ 0.023956872522830963, -0.014050156809389591, -0.005978790111839771, 0.045383188873529434, 0.0350106805562973, -0.025249959900975227, 0.021537547931075096, -0.010017949156463146, -0.017602670937776566, 0.008627532981336117, 0.021398507058620453, -0.01750534027814865, 0.007445679046213627, -...
1496/B
null
1496
Codeforces Round 706 (Div. 2)
CF
1,615,377,900
2,021
B
1
256
Max and Mex
You are given a multiset $$$S$$$ initially consisting of $$$n$$$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times. You will perform the following operation $$$k$$$ times: - Add the element $$$\lceil\frac{a+b}{2}\rceil$$$ (rounded up) into $$$S$$$, where $$$a = \operat...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 10^5$$$, $$$0\le k\le 10^9$$$) — the initial siz...
For each test case, print the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done.
null
In the first test case, $$$S=\{0,1,3,4\}$$$, $$$a=\operatorname{mex}(S)=2$$$, $$$b=\max(S)=4$$$, $$$\lceil\frac{a+b}{2}\rceil=3$$$. So $$$3$$$ is added into $$$S$$$, and $$$S$$$ becomes $$$\{0,1,3,3,4\}$$$. The answer is $$$4$$$. In the second test case, $$$S=\{0,1,4\}$$$, $$$a=\operatorname{mex}(S)=2$$$, $$$b=\max(S)...
[ { "input": "5\n4 1\n0 1 3 4\n3 1\n0 1 4\n3 0\n0 1 4\n3 2\n0 1 2\n3 2\n1 2 3", "output": "4\n4\n3\n5\n3" } ]
Let $$$a=\max(S),b=\operatorname{mex}(S)$$$. When $$$k=0$$$, the answer is $$$n$$$. Otherwise if $$$b>a$$$, then $$$b=a+1$$$ , so $$$\lceil\frac{a+b}{2}\rceil=b$$$ . It's not hard to find out that $$$\max(S\cup\{b\})=b,\operatorname{mex}(S\cup\{b\})=b+1$$$, so the set $$$S$$$ always satisfies $$$\max(S)+1=\operatorname...
[ 0.02029426023364067, -0.005842195358127356, -0.012638342566788197, 0.0052588870748877525, 0.023976393043994904, -0.019480060786008835, 0.00341782090254128, 0.027221044525504112, 0.014461180195212364, 0.02846057526767254, -0.0028770456556230783, -0.014461180195212364, -0.0418766625225544, -...