Submission #1316964

#TimeUsernameProblemLanguageResultExecution timeMemory
1316964LIAGrowing Vegetables is Fun 5 (JOI24_vegetables5)C++17
0 / 100
667 ms18632 KiB
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define v vector
#define lp(i,s,e) for(int i = s;i<e;++i)
int n;
v<ll> a, b, c;

bool can_match(v<ll>& plants, v<ll>& pots, ll x) {
  lp(i, 0, n) {
    if (abs(plants[i] - pots[i]) > x) return false;
  }
  return true;
}

bool check(ll x) {
  v<ll> p1, p2;
  lp(i, 0, n) p1.push_back(a[i]);
  lp(i, n, 2 * n) p2.push_back(a[i]);
  sort(p1.begin(), p1.end());
  sort(p2.begin(), p2.end());
  if (can_match(p1, b, x) && can_match(p2, c, x)) return true;
  if (can_match(p1, c, x) && can_match(p2, b, x)) return true;
  return false;
}

int main() {
  cin >> n;
  a.resize(2 * n);
  lp(i, 0, 2 * n) cin >> a[i];
  b.resize(n);
  lp(i, 0, n) cin >> b[i];
  c.resize(n);
  lp(i, 0, n) cin >> c[i];
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll lo = 0, hi = 2e9, ans = 2e9;
  while (lo <= hi) {
    ll mid = lo + (hi - lo) / 2;
    if (check(mid)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}
#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...