問題一覧 > 通常問題

No.3058 Deque and Brackets

レベル : / AI推定難易度 : 2350 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 32
作問者 : 👑 tute7627 / テスター : 👑 rin204 SPD_9X2
お気に入りにしたユーザー ProblemId : 10994 / 自分の提出
問題文最終更新日: 2025-03-12 02:47:07
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 460 (順位表) の他の問題:

Problem Statement

A string satisfying any of the following conditions is defined as a correct bracket sequence.

  • The empty string
  • The string obtained by concatenating (, $A$, ) in this order, for some correct bracket sequence $A$
  • The string obtained by concatenating $A$, $B$ in this order, for some non-empty correct bracket sequences $A$, $B$

There is an empty string $S$. Initially, your score is $0$, and you will now perform the following operation a total of $2N$ times.

  • In the $i$-th operation, choose one of the following. Here, $C_i$ is ( or ).
    • Add the character $C_i$ to the beginning of $S$, and add $L_i$ to the score.
    • Add the character $C_i$ to the end of $S$, and add $R_i$ to the score.

When performing the operations so that the string $S$ after the $2N$ operations is a correct bracket sequence, find the maximum possible final score.

It can be shown that, under the constraints of this problem, there exists a sequence of operations such that the string $S$ after the $2N$ operations is a correct bracket sequence.

Input

$N$
$C_1\ L_1\ R_1$
$C_2\ L_2\ R_2$
$\vdots$
$C_{2N}\ L_{2N}\ R_{2N}$

  • $N, L_i, R_i$ are integers.
  • $1 \le N \le 10^5$
  • $1 \le L_i,R_i \le 10^9$
  • $C_i$ is ( or ).
  • Among $C_1,C_2,\dots,C_{2N}$, each of ( and ) appears exactly $N$ times.

Output

Output the maximum score. Print a newline at the end.

Sample

Sample 1
Input
2
( 5 1
) 10 1
( 1 7
) 100 100
Output
116

By performing the operations as follows, the score becomes $116$.

  • In the $1$-st operation, add to the beginning. $S=$ ( and the score becomes $5$.
  • In the $2$-nd operation, add to the beginning. $S=$ )( and the score becomes $15$.
  • In the $3$-rd operation, add to the beginning. $S=$ ()( and the score becomes $16$.
  • In the $4$-th operation, add to the end. $S=$ ()() and the score becomes $116$.

Sample 2
Input
7
) 5 83
( 39 31
) 96 66
) 53 55
( 22 42
) 82 72
) 89 71
( 98 47
( 8 32
( 19 75
) 69 63
( 29 78
( 26 37
) 48 66
Output
890

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。