Submission

Status:

[PPP-SSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: tnka4_

Problemset: anna

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-09 15:30:08

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

#define ll long long int

bool check(ll a, ll b, vector<ll>seq) {
    vector<ll> p = {a*b, a+b, a-b, a%b, a/b};
    sort(p.rbegin(), p.rend());
    if (p == seq) {
        return true;
    } else {return false;}
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<vector<ll>> seq(n, vector<ll>(5));
    for (int i=0; i<n; i++) {
        for (int j=0; j<5; j++) {
            cin >> seq[i][j];
        }
    }
    for (int i=0; i<n; i++) {
        sort(seq[i].rbegin(), seq[i].rend());
        ll x = seq[i][0], y = seq[i][1];
        ll a, b;
        if (abs(x-y) == 1) {
            a = y; b = 1;
            if (check(a, b, seq[i])) {
                cout << a << " " << b << endl;
                continue;
            }
        }
        if (y*y-4*x >= 0) {
            a = (y + sqrt(y*y-4*x)) / 2;
            b = (y - sqrt(y*y-4*x)) / 2;
            if (b>a) swap(a,b);
        } else {
            cout << "0 0\n";
            continue;
        }
        if (check(a, b, seq[i])) {
            cout << a << " " << b << endl;
            continue;
        }
        cout << "0 0\n";
    }
}