Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- const int N = 200200;
- ll f(int a, int b) {
- return (a - b) * 1ll * (a - b);
- }
- ll f(int a, int b, int c) {
- return f(a, b) + f(a, c) + f(b, c);
- }
- ll solve(vector<int>& a, vector<int>& b, vector<int>& c) {
- ll ans = 5e18;
- int j = 0;
- int k = 0;
- for (int i = 0; i < size(a); i++) {
- while (j < size(b) && b[j] < a[i]) j++;
- if (j < size(b)) {
- k = max(0, k - 1);
- ll pre = f(a[i], b[j], c[k]);
- ll cur = pre;
- ans = min(ans, pre);
- while (k < size(c)) {
- cur = f(a[i], b[j], c[k]);
- if (cur > pre) break;
- ans = min(ans, cur);
- pre = cur;
- k++;
- }
- } else {
- break;
- }
- }
- return ans;
- }
- void solve() {
- int a, b, c;
- cin >> a >> b >> c;
- vector<int> arr(a), brr(b), crr(c);
- for (int i = 0; i < a; i++) cin >> arr[i];
- for (int i = 0; i < b; i++) cin >> brr[i];
- for (int i = 0; i < c; i++) cin >> crr[i];
- sort(all(arr));
- sort(all(brr));
- sort(all(crr));
- ll ans = 5e18;
- ans = min(ans, solve(arr, brr, crr));
- ans = min(ans, solve(arr, crr, brr));
- ans = min(ans, solve(brr, crr, arr));
- ans = min(ans, solve(brr, arr, crr));
- ans = min(ans, solve(crr, arr, brr));
- ans = min(ans, solve(crr, brr, arr));
- cout << ans << '\n';
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement