// header file
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// macros
#define endl "\n"
#define ll long long
#define mp make_pair
#define ins insert
#define lb lower_bound
#define pb push_back
#define ub upper_bound
#define lll __int128
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n;
cin >> n;
int a[2 * n + 5];
for(int i = 1; i <= 2 * n; ++i)
cin >> a[i];
int b[n + 5], c[n + 5];
for(int i = 1; i <= n; ++i)
cin >> b[i];
for(int i = 1; i <= n; ++i)
cin >> c[i];
sort(b + 1, b + n + 1);
sort(c + 1, c + n + 1);
// choose a contiguous segment L to R such that we use one color
// N^2 approach -> pair greedily (sorted)
int res = 1e9;
for(int i = 1; i + n <= 2 * n + 1; ++i) {
vector<int> blue, red;
for(int j = 1; j < i; ++j) {
blue.pb(a[j]);
}
for(int j = i; j < i + n; ++j) {
red.pb(a[j]);
}
for(int j = i + n; j <= 2 * n; ++j) {
blue.pb(a[j]);
}
sort(blue.begin(), blue.end());
sort(red.begin(), red.end());
int mx = 0;
for(int k = 1; k <= n; ++k) {
mx = max({mx, abs(blue[k - 1] - b[k]), abs(red[k - 1] - c[k])});
}
res = min(res, mx);
mx = 0;
swap(red, blue);
for(int k = 1; k <= n; ++k) {
mx = max({mx, abs(blue[k - 1] - b[k]), abs(red[k - 1] - c[k])});
}
res = min(res, mx);
}
cout << res << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
452 KB |
Output is correct |
26 |
Correct |
165 ms |
344 KB |
Output is correct |
27 |
Correct |
161 ms |
344 KB |
Output is correct |
28 |
Correct |
81 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
176 ms |
592 KB |
Output is correct |
31 |
Correct |
158 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
9 ms |
348 KB |
Output is correct |
34 |
Correct |
171 ms |
588 KB |
Output is correct |
35 |
Correct |
167 ms |
344 KB |
Output is correct |
36 |
Correct |
165 ms |
572 KB |
Output is correct |
37 |
Correct |
67 ms |
600 KB |
Output is correct |
38 |
Correct |
76 ms |
348 KB |
Output is correct |
39 |
Correct |
93 ms |
348 KB |
Output is correct |
40 |
Correct |
171 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5087 ms |
21164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
452 KB |
Output is correct |
26 |
Correct |
165 ms |
344 KB |
Output is correct |
27 |
Correct |
161 ms |
344 KB |
Output is correct |
28 |
Correct |
81 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
176 ms |
592 KB |
Output is correct |
31 |
Correct |
158 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
9 ms |
348 KB |
Output is correct |
34 |
Correct |
171 ms |
588 KB |
Output is correct |
35 |
Correct |
167 ms |
344 KB |
Output is correct |
36 |
Correct |
165 ms |
572 KB |
Output is correct |
37 |
Correct |
67 ms |
600 KB |
Output is correct |
38 |
Correct |
76 ms |
348 KB |
Output is correct |
39 |
Correct |
93 ms |
348 KB |
Output is correct |
40 |
Correct |
171 ms |
532 KB |
Output is correct |
41 |
Execution timed out |
5087 ms |
21164 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |