#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, exist = 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 sl = 1;
pre = cur;
}
if(sl >= 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 solve()':
Main.cpp:51:49: warning: unused variable 'exist' [-Wunused-variable]
51 | int best = 0, cur = 0, pre = 0, sl = 0, exist = 0;
| ^~~~~
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 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 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 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 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 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 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
8528 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 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 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |