結果

問題 No.1435 Mmm......
ユーザー titia
提出日時 2021-03-20 00:20:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 70,940 KB
最終ジャッジ日時 2024-11-19 03:26:58
合計ジャッジ時間 38,111 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import heapq

N=int(input())
A=list(map(int,input().split()))

MIN=[]

heapq.heappush(MIN,(A[0],0))
heapq.heappush(MIN,(A[1],1))

MAX=[]
heapq.heappush(MAX,(-A[0],0))
heapq.heappush(MAX,(-A[1],1))


ANS=0
now=1
for i in range(N):
    #print(i,now)
    
    while True:
        if now==N:
            ANS+=now-i-1
            break
        
        
        while MIN[0][1]<i:
            heapq.heappop(MIN)
        x,xi=heapq.heappop(MIN)

        while MIN[0][1]<i:
            heapq.heappop(MIN)
        y,yi=heapq.heappop(MIN)

        k=x+y

        while MAX[0][1]<i:
            heapq.heappop(MAX)

        l,li=heapq.heappop(MAX)

        if -l>k:
            ANS+=now-i-1
            heapq.heappush(MIN,(x,xi))
            heapq.heappush(MIN,(y,yi))
            heapq.heappush(MAX,(l,li))
            break
        else:
            now+=1
            heapq.heappush(MIN,(x,xi))
            heapq.heappush(MIN,(y,yi))
            heapq.heappush(MAX,(l,li))

            if now==N:
                continue

            heapq.heappush(MIN,(A[now],now))
            heapq.heappush(MAX,(-A[now],now))
            
    #print(i,now,k,l,MIN,MAX)

print(ANS)

            
        

    

    
    
    
0