Submission #1074039

#TimeUsernameProblemLanguageResultExecution timeMemory
1074039joelgun14Growing Vegetables is Fun 5 (JOI24_vegetables5)C++17
30 / 100
5087 ms21164 KiB
// 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 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...