CF2169E.Points Selection

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing with points on the XY plane. Initially, there are nn points on the plane: the ii-th point is located at (xi,yi)(x_i, y_i) and has a cost of cic_i.

The game consists of two stages:

  1. First, Alice selects some points (possibly none, but not all) and removes them from the field.
  2. Then, Bob draws a rectangle with sides parallel to the coordinate axes, such that all remaining points lie inside or on the boundary of this rectangle. The rectangle can degenerate into a line segment or even a point.

After that, the game ends and the total score is calculated. The total score of the game is the sum of the costs of the removed points by Alice and the perimeter of the rectangle drawn by Bob. Alice wants to maximize the score, while Bob wants to minimize it.

Determine the total score of the game if both Alice and Bob play optimally.

The perimeter of the rectangle is equal to the sum of the lengths of all its four sides. Therefore, even if the rectangle degenerates into a line segment of length kk, its perimeter will be 2k2k. The perimeter of a rectangle that degenerates into a point is 00.

爱丽丝和鲍勃正在 XY 平面上玩点的游戏。初始时,平面上有 nn 个点:第 ii 个点位于 (xi,yi)(x_i, y_i),其代价为 cic_i。

游戏分为两个阶段:

  1. 首先,爱丽丝选择若干个点(可以一个都不选,但不能全部选)并将其从平面上移除;
  2. 接着,鲍勃画一个边与坐标轴平行的矩形,使得所有剩余的点均位于该矩形内部或边界上。该矩形可以退化为一条线段,甚至一个点。

此后游戏结束,并计算总得分。游戏总得分为:爱丽丝移除的点的代价之和,加上鲍勃所画矩形的周长。爱丽丝希望最大化总得分,而鲍勃希望最小化总得分。

若双方均采取最优策略,请确定游戏的总得分。

矩形的周长等于其四条边长度之和。因此,即使矩形退化为一条长度为 kk 的线段,其周长也为 2k2k;而退化为一个点的矩形,其周长为 00。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5) — the number of points on the plane.

The second line of each test case contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (0≤xi≤10150 \le x_i \le 10^{15}) — the xx-coordinates of the points.

The third line contains nn integers y1,y2,…,yny_1, y_2, \dots, y_n (0≤yi≤10150 \le y_i \le 10^{15}) — the yy-coordinates of the points.

The fourth line contains nn integers c1,c2,…,cnc_1, c_2, \dots, c_n (0≤ci≤1090 \le c_i \le 10^9) — the costs of the points.

Additional constraints on the input:

  • in one test case, all points are pairwise distinct;
  • the total number of points across all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)——平面上点的数量。

每个测试用例的第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(0≤xi≤10150 \le x_i \le 10^{15})——各点的 xx 坐标。

第三行包含 nn 个整数 y1,y2,…,yny_1, y_2, \dots, y_n(0≤yi≤10150 \le y_i \le 10^{15})——各点的 yy 坐标。

第四行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \dots, c_n(0≤ci≤1090 \le c_i \le 10^9)——各点的代价。

输入的额外约束条件:

  • 在一个测试用例中,所有点两两互不相同;
  • 所有测试用例中点的总数不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output a single integer — the final score of the game if both Alice and Bob play optimally.

对于每个测试用例,输出一个整数——即当爱丽丝和鲍勃均采取最优策略时,游戏的最终得分。

输入输出样例

  • 输入#1

    4
    1
    42
    42
    1000
    4
    5 10 5 0
    0 5 10 5
    1 1 1 1
    4
    6 7 8 9
    3 3 3 3
    9 0 9 0
    2
    1000000000 10
    10 1000000000
    12345 54321

    输出#1

    0
    40
    22
    3999999960

说明/提示

In the first test case, there is only one point, and Alice cannot remove it. Then Bob constructs the rectangle (1,1)−(1,1)(1, 1) - (1, 1) with a perimeter of 00.

In the second test case, it is optimal for Alice not to remove any points. Then Bob constructs the rectangle (0,0)−(10,10)(0, 0) - (10, 10) with a perimeter of 4040.

In the third test case, it is optimal for Alice to remove the first and third points. Then Bob constructs the rectangle (7,3)−(9,3)(7, 3) - (9, 3) with a perimeter of 44. The total score will be 9+9+4=229 + 9 + 4 = 22.

在第一个测试用例中,只有一个点,Alice 无法移除它。随后 Bob 构造矩形 (1,1)−(1,1)(1, 1) - (1, 1),其周长为 00。

在第二个测试用例中,Alice 最优策略是不移除任何点。随后 Bob 构造矩形 (0,0)−(10,10)(0, 0) - (10, 10),其周长为 4040。

在第三个测试用例中,Alice 的最优策略是移除第一个和第三个点。随后 Bob 构造矩形 (7,3)−(9,3)(7, 3) - (9, 3),其周长为 44。总得分为 9+9+4=229 + 9 + 4 = 22。

输入解题思路,AI测评打分。不知道怎么写?

首页