Submission #1173156

#TimeUsernameProblemLanguageResultExecution timeMemory
1173156AmirAli_H1Growing Vegetables is Fun 5 (JOI24_vegetables5)C++20
30 / 100
5094 ms14060 KiB
// In the name of Allah #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 6e5 + 7; const ll oo = 1e9 + 4; int n; ll A[maxn], A1[maxn], A2[maxn]; vector<ll> lsx; void solve() { cin >> n; for (int i = 0; i < (2 * n); i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> A1[i]; for (int i = 0; i < n; i++) cin >> A2[i]; sort(A1, A1 + n); sort(A2, A2 + n); ll ans = oo; for (int i = 0; i < (2 * n); i++) { ll mx = 0; lsx.clear(); for (int j = i; j < i + n; j++) { int R = j; if (R >= 2 * n) R -= 2 * n; lsx.pb(A[R]); } sort(all(lsx)); for (int i = 0; i < n; i++) mx = max(mx, abs(A1[i] - lsx[i])); lsx.clear(); for (int j = i + n; j < i + (2 * n); j++) { int R = j; if (R >= 2 * n) R -= 2 * n; lsx.pb(A[R]); } sort(all(lsx)); for (int i = 0; i < n; i++) mx = max(mx, abs(A2[i] - lsx[i])); ans = min(ans, mx); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...