結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー t98slider
提出日時 2025-11-21 21:26:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 201,376 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-21 21:26:25
合計ジャッジ時間 3,111 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vector<ll> a, b;
        for(int i = 0; i < n; i++){
            ll v;
            cin >> v;
            if(v >= 0) a.emplace_back(v);
            else b.emplace_back(v);
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        if(!a.empty() && !b.empty()){
            cout << a[0] * b.back() << '\n';
            continue;
        }
        ll ans = 1ll << 60;
        for(int i = 0; i < a.size(); i++){
            ans = min(ans, a.back() * a[i]);
        }
        for(int i = 0; i < b.size(); i++){
            ans = max(ans, b[i] * b.back());
        }
        cout << ans << '\n';
    }
}
0