結果
| 問題 | 
                            No.1095 Smallest Kadomatsu Subsequence
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ttr
                         | 
                    
| 提出日時 | 2020-06-26 22:29:53 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,010 ms / 2,000 ms | 
| コード長 | 489 bytes | 
| コンパイル時間 | 97 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 39,204 KB | 
| 最終ジャッジ日時 | 2024-07-04 22:14:20 | 
| 合計ジャッジ時間 | 9,663 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
import heapq
N = int(input())
A = [int(a) for a in input().split()]
ans = 10**9
l = A[0]
h = []
for i in range(2, N):
    heapq.heappush(h, (A[i], i))
for i in range(1, N-1):
    while len(h) > 0 and h[0][1] <= i:
        heapq.heappop(h)
    if len(h) == 0:
        break
    if l < A[i] and h[0][0] < A[i]:
        ans = min(ans, l+A[i]+h[0][0])
    elif A[i] < l and A[i] < h[0][0]:
        ans = min(ans, l+A[i]+h[0][0])
    l = min(l, A[i])
if ans == 10**9:
    ans = -1
print(ans)
            
            
            
        
            
ttr