結果
| 問題 | No.1095 Smallest Kadomatsu Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-28 20:29:35 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 489 bytes |
| 記録 | |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 112,768 KB |
| 最終ジャッジ日時 | 2026-05-28 20:29:39 |
| 合計ジャッジ時間 | 4,225 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 25 |
ソースコード
import heapq
ans=1<<60;n=int(input())
a=list(map(int,input().split()))
hq1=[];hq2=[]
for i in range(1,n):
heapq.heappush(hq1,(a[i],i))
heapq.heappush(hq2,(-a[i],i))
c=a[0];d=a[0]
for i in range(1,n-1):
if a[i]>c and a[i]>hq1[0][0]:
ans=min(ans,a[i]+c+hq1[0][0])
if a[i]<d and a[i]<-hq2[0][0]:
ans=min(ans,a[i]+d+-hq2[0][0])
if hq1[0][1]==i:
heapq.heappop(hq1)
if hq2[0][1]==i:
heapq.heappop(hq2)
if ans==1<<60:
ans=-1
print(ans)