結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー Iroha_3856
提出日時 2025-10-27 18:33:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 361 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 104,412 KB
最終ジャッジ日時 2025-11-21 20:51:47
合計ジャッジ時間 3,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
	INF = 10**18
	N = int(input())
	A = list(map(int, input().split()))
	M = max(A)
	m = min(A)
	if 0 in A:
		print(0)
	else:
		if M > 0 and m > 0:
			print(M * m)
		elif M < 0 and m < 0:
			print(M * m)
		else:
			p, q = -INF, INF
			for a in A:
				if a < 0: p = max(p, a)
				else: q = min(q, a)
			print(p*q)

for _ in range(int(input())): solve()
0