#include <bits/stdc++.h>
#define Y8o "Growing Vegetables is Fun 5"
#define maxn (int) 3e5 + 5
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
//#define f first
//#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
}
void ctime() {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, N;
int a[maxn], b[maxn], c[maxn];
int x[maxn];
void solve() {
cin >> n, N = 2*n;
fi(i, 1, N) cin >> a[i];
fi(i, 1, n) cin >> b[i];
fi(i, 1, n) cin >> c[i];
assert(n <= 5);
fi(i, 1, N) x[i] = i;
int ans = 2e9;
do {
int best = 0, cur = 0, pre = 0, sl = 0, mx = 0;
fi(i, 1, N) {
if(x[i] <= n) best = max(best, abs(b[x[i]] - a[i])), cur = 1;
else best = max(best, abs(c[x[i] - n] - a[i])), cur = 2;
if(pre == cur) sl ++;
else mx = max(mx, sl), sl = 1;
pre = cur;
}
if(mx >= n) ans = min(ans, best);
} while(next_permutation(x + 1, x +N + 1));
cout << ans;
}
int main() {
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
ctime();
return 0;
}
Compilation message
Main.cpp: In function 'void iof()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4432 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4600 KB |
Output is correct |
6 |
Correct |
65 ms |
4560 KB |
Output is correct |
7 |
Correct |
68 ms |
4568 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
69 ms |
4556 KB |
Output is correct |
10 |
Correct |
62 ms |
4564 KB |
Output is correct |
11 |
Correct |
62 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4432 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4600 KB |
Output is correct |
6 |
Correct |
65 ms |
4560 KB |
Output is correct |
7 |
Correct |
68 ms |
4568 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
69 ms |
4556 KB |
Output is correct |
10 |
Correct |
62 ms |
4564 KB |
Output is correct |
11 |
Correct |
62 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
13 |
Runtime error |
7 ms |
8784 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4432 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4600 KB |
Output is correct |
6 |
Correct |
65 ms |
4560 KB |
Output is correct |
7 |
Correct |
68 ms |
4568 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
69 ms |
4556 KB |
Output is correct |
10 |
Correct |
62 ms |
4564 KB |
Output is correct |
11 |
Correct |
62 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
13 |
Runtime error |
7 ms |
8784 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
30 ms |
5456 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4432 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4600 KB |
Output is correct |
6 |
Correct |
65 ms |
4560 KB |
Output is correct |
7 |
Correct |
68 ms |
4568 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
69 ms |
4556 KB |
Output is correct |
10 |
Correct |
62 ms |
4564 KB |
Output is correct |
11 |
Correct |
62 ms |
4432 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
13 |
Runtime error |
7 ms |
8784 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |