File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Contests/Mail.Ru Cup 2018 Round 1/Explanation Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ Initially, the mex = 0
2
+
3
+ At each step,
4
+
5
+ Case 1 - Element > mex
6
+
7
+ This is not possible as the element has to be at most the Mex.
8
+
9
+ If this happens, it's a mistake. Stop.
10
+
11
+ Case 2 - Element = mex
12
+
13
+ Then, mex is not mex + 1
14
+
15
+ Case 3 - Element < mex
16
+
17
+ This is allowed. Just move on to the next step.
18
+
19
+ ----------------------------------------------------
20
+
21
+ int main()
22
+ {
23
+ int no_of_elements;
24
+ cin >> no_of_elements;
25
+
26
+ int mex_so_far = 0;
27
+ for(int i = 1; i <= no_of_elements; i++)
28
+ {
29
+ int element;
30
+ cin >> element;
31
+
32
+ if(element > mex_so_far)
33
+ {
34
+ cout << i;
35
+ return 0;
36
+ }
37
+ else if(element == mex_so_far)
38
+ {
39
+ mex_so_far++;
40
+ }
41
+ }
42
+
43
+ cout << "-1";
44
+ return 0;
45
+ }
You can’t perform that action at this time.
0 commit comments