結果
問題 | No.3058 Deque and Brackets |
ユーザー |
![]() |
提出日時 | 2025-03-16 00:49:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 630 ms / 2,000 ms |
コード長 | 593 bytes |
コンパイル時間 | 433 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 72,448 KB |
最終ジャッジ日時 | 2025-03-16 00:49:21 |
合計ジャッジ時間 | 12,621 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import sys input = sys.stdin.readline from heapq import heappop,heappush N=int(input()) X=[input().split() for i in range(2*N)] X.reverse() l=0 r=0 ANS=0 H=[] for s,x,y in X: x=int(x) y=int(y) if s==")": if y>=x: r+=1 ANS+=y else: ANS+=x heappush(H,(x-y)) l-=1 else: if x>=y: l+=1 ANS+=x else: ANS+=y heappush(H,(y-x)) r-=1 if l<0 or r<0: k=heappop(H) ANS-=k l+=1 r+=1 print(ANS)