Submission

Status:

[PPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Ryuthin94

Problemset: anna

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-11 15:27:28

#include <bits/stdc++.h>
using namespace std;

void solve(vector<long long> a)
{
    vector<long long> target = a;
    sort(target.begin(), target.end());

    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (i == j)
                continue;

            long long S = a[i];
            long long D = a[j];

            if ((S + D) % 2 != 0 || (S - D) % 2 != 0)
                continue;

            long long A = (S + D) / 2;
            long long B = (S - D) / 2;

            if (A <= B || B < 1)
                continue;

            vector<long long> generated = {
                A + B,
                A - B,
                A * B,
                A % B,
                A / B};

            sort(generated.begin(), generated.end());

            if (generated == target)
            {
                cout << A << " " << B;
                return;
            }
        }
    }

    cout << "0 0";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    while (n--)
    {
        vector<long long> a(5);
        for (int i = 0; i < 5; i++)
        {
            cin >> a[i];
        }
        solve(a);
        cout << "\n";
    }
}