Browse Source

...

master^2
nwerc-082 2 years ago
parent
commit
ad2e8c1c76
2 changed files with 67 additions and 0 deletions
  1. 38
    0
      F.cpp
  2. 29
    0
      F.py

+ 38
- 0
F.cpp View File

@@ -0,0 +1,38 @@
1
+#include <algorithm>
2
+#include <functional>
3
+#include <iostream>
4
+#include <set>
5
+#include <vector>
6
+
7
+using namespace std;
8
+
9
+long f(vector<long>& l)
10
+{
11
+  long m = 0; set<long, greater<long>> s = {0};
12
+  for(auto x : l) {
13
+    // cerr << "x = " << x << endl;
14
+    if (s.count(x) == 0) {
15
+      m = max(m, min(*s.begin(), x));
16
+      s.insert(x);
17
+    } else {
18
+      s.erase(x);
19
+      m = max(m, min(*s.begin(), x));
20
+    }
21
+    // cerr << "m = " << m << endl;
22
+  }
23
+  return m;
24
+}
25
+
26
+int main()
27
+{
28
+  long n; cin >> n; vector<long> l1(n), l2(n);
29
+  for (long i = 0; i < n; ++i) cin >> l1[i];
30
+  for (long i = 0; i < n; ++i) cin >> l2[i];
31
+  set<long> s2(begin(l2), end(l2));
32
+  set<long, greater<long>> s; vector<long> l1_, l2_;
33
+  for (auto x : l1) if (s2.count(x) == 1) s.insert(x);
34
+  for (auto x : l1) if (s.count(x) == 0) l1_.push_back(x);
35
+  for (auto x : l2) if (s.count(x) == 0) l2_.push_back(x);
36
+  long m = *s.begin();
37
+  cout << max(m, max(f(l1_), f(l2_))) << endl;
38
+}

+ 29
- 0
F.py View File

@@ -0,0 +1,29 @@
1
+MOVED_TO_CPP
2
+
3
+from __future__ import print_function
4
+import sys
5
+
6
+def f(l):
7
+  m, s, ms = 0, set(), 0
8
+  for x in l:
9
+    if x not in s:
10
+      s.add(x)
11
+      ms = max(x, ms)
12
+    else:
13
+      s.remove(x)
14
+      ms = ...
15
+    if ms > x:
16
+      m = max(m, x)
17
+    else:
18
+      m = max(m, ms)
19
+  return m
20
+
21
+n   = int(sys.stdin.readline())
22
+l1  = map(int, sys.stdin.readline().split())
23
+l2  = map(int, sys.stdin.readline().split())
24
+s2  = set(l2)
25
+s   = [ x for x in l1 if x in s2 ]
26
+l1  = [ x for x in l1 if x not in s ]
27
+l2  = [ x for x in l2 if x not in s ]
28
+m   = max(s)
29
+print(max(m, max(f(l1), f(l2))))

Loading…
Cancel
Save