結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー a01sa01to
提出日時 2025-12-03 00:44:38
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 624 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,339 ms
コンパイル使用メモリ 281,988 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-03 00:44:45
合計ジャッジ時間 6,579 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    if (a.front() >= 0 || a.back() <= 0) {
      cout << a.front() * a.back() << '\n';
    }
    else {
      auto it1 = lower_bound(a.begin(), a.end(), 0LL);
      assert(it1 != a.begin());
      auto it2 = prev(it1);
      cout << *it1 * *it2 << '\n';
    }
  }
  return 0;
}
0