結果
問題 |
No.851 テストケース
|
ユーザー |
|
提出日時 | 2025-05-26 19:52:35 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,217 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 53,988 KB |
最終ジャッジ日時 | 2025-05-26 19:52:38 |
合計ジャッジ時間 | 2,622 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 18 WA * 2 |
ソースコード
import sys from itertools import combinations lines = [line.rstrip('\n').strip() for line in sys.stdin] # Check for the error format (N followed by N numbers in one line) if len(lines) == 2: n_str = lines[0] second_line = lines[1] try: n = int(n_str) parts = second_line.split() if len(parts) == n: print("assert") sys.exit() except: pass # Not the error format, proceed to process # Process the correct format try: n = int(lines[0]) nums = [] for line in lines[1:1 + n]: # Read next n lines, ignoring extra lines parts = line.split() if not parts: num = 0 # Handle empty lines as 0, though input is assumed correct else: num = int(parts[0]) nums.append(num) # Generate all possible sums of two distinct elements sum_set = set() for a, b in combinations(nums, 2): sum_set.add(a + b) # Sort in descending order and find the second largest sorted_sums = sorted(sum_set, reverse=True) if len(sorted_sums) >= 2: print(sorted_sums[1]) else: print(sorted_sums[0] if sorted_sums else 0) except: print("assert")