結果

問題 No.1435 Mmm......
ユーザー titiatitia
提出日時 2021-03-20 00:21:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,140 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,960 KB
実行使用メモリ 126,396 KB
最終ジャッジ日時 2024-04-29 20:21:41
合計ジャッジ時間 21,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 47 ms
52,352 KB
testcase_03 AC 43 ms
52,864 KB
testcase_04 AC 42 ms
52,480 KB
testcase_05 AC 42 ms
52,736 KB
testcase_06 AC 734 ms
94,464 KB
testcase_07 AC 807 ms
97,280 KB
testcase_08 AC 1,026 ms
103,552 KB
testcase_09 AC 992 ms
100,608 KB
testcase_10 AC 891 ms
97,152 KB
testcase_11 AC 858 ms
97,408 KB
testcase_12 AC 810 ms
94,336 KB
testcase_13 AC 847 ms
94,720 KB
testcase_14 AC 601 ms
88,448 KB
testcase_15 AC 1,033 ms
103,808 KB
testcase_16 AC 924 ms
97,536 KB
testcase_17 AC 683 ms
90,496 KB
testcase_18 AC 928 ms
104,448 KB
testcase_19 AC 730 ms
95,104 KB
testcase_20 AC 974 ms
100,480 KB
testcase_21 AC 608 ms
126,396 KB
testcase_22 AC 1,140 ms
117,880 KB
testcase_23 AC 995 ms
100,052 KB
testcase_24 AC 900 ms
99,992 KB
testcase_25 AC 923 ms
100,200 KB
testcase_26 AC 900 ms
100,312 KB
testcase_27 AC 1,081 ms
100,060 KB
権限があれば一括ダウンロードができます

ソースコード

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