#546. 「Nowcoder多校 2019 Day1」Points Division

「Nowcoder多校 2019 Day1」Points Division

题目描述

Bobo has a set P of n distinct points (x1,y1),(x2,y2),,(xn,yn) (x_1, y_1), (x_2, y_2), \dots, (x_n, y_n) .
The i-th point has two weights ai a_i and bi b_i .
He wants to partition the points into two sets A and B (That is, AB=P A \cup B = P and AB= A \cap B = \emptyset .
A partition (A, B) is valid if and only if there exists no iA i \in A and jB j \in B where xixj x_i \geq x_j ​ and yiyj y_i \leq y_j .
Find the maximum of $ \left(\sum_{i \in A} a_i \right) + \left(\sum_{j \in B} b_j\right) $ among all valid partitions (A, B).

输入格式

The input consists of several test cases and is terminated by end-of-file.

The first line of each test cases contains an integer n. The i-th of the following n lines contains four integers xi,yi,ai,bi x_i, y_i, a_i, b_i .

  • 1n105 1 \leq n \leq 10^5
  • 1xi,yi,ai,bi109 1 \leq x_i, y_i, a_i, b_i \leq 10^9
  • (xi,yi)(xj,yj) (x_i, y_i) \neq (x_j, y_j) for all ij i \neq j
  • The sum of n does not exceed 5×105 5 \times 10^5 .

输出格式

For each test case, print an integer which denotes the result.

样例

样例输入

2
1 2 1 9
2 1 9 1
1
1 1 2 3
4
1 1 1 5
1 2 2 6
2 1 3 7
2 2 4 8

样例输出

10
3
26