CF1860F Evaluate RBS
题目描述
现有 $2n$ 个形如 $(a, b, c)$ 的三元组,其中 $a, b$ 均为正整数, $c$ 是字符 `(` 或 `)`(左圆括号或右圆括号)。其中恰有 $n$ 个三元组的 $c$ 为 `(`,另外 $n$ 个为 `)`。
对于两个正实数 $x,y$ ,记一个三元组的特征值为 $\lambda = ax+by$ 。你需要选择 $x,y$ 并对三元组按其特征值升序排序。若多个三元组的特征值相同,可以选择随意排列。
问,是否存在一种选法,使得排序后的序列能让 $c$ 组成一个合法的括号序列。
输入格式
第一行一个整数 $t(1\leq t \leq 1500)$ 表示有 $t$ 组数据。
接下来的每组数据,第一行一个整数 $n(1\leq n \leq 1500)$ 表示有 $2n$ 个三元组。
每组数据的第 $i$ 行输入 $a_i,b_i,c_i$ 并用空格分割。三个参数的意义见上,其中 $1 \leq a,b\leq 10^6$ 且 $c$ 是一个字符。
输入数据一定满足 $n$ 个三元组的 $c$ 为 `(`,另外 $n$ 个为 `)`。
输出格式
对于每组数据,每行输出 `YES` 或 `NO` 表示是否存在合法的解。
说明/提示
In the first testcase, you can choose $ x = 10, y = 0.1 $ . The values for tuples will be $ 10 \cdot 1 + 0.1 \cdot 4 = 10.4 $ and $ 10 \cdot 2 + 0.1 \cdot 3 = 20.3 $ . Thus, the first tuple will go first, then the second one, making the bracket sequence "()", which is regular.
In the second testcase, you can't choose positive $ x $ and $ y $ such that the opening brackets gets assigned a value less or equal to the value of the closing bracket.
In the fourth testcase, you can choose $ x = 0.6, y = 0.55 $ . The bracket sequence is "(()(()))".