QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#17942. 최고의 초콜릿 성지순례

الإحصائيات

Coco 的村庄以拥有许多巧克力店而闻名。在这个村庄中,对于每个整数 $x$ ($1 \le x \le N$) 和 $y$ ($1 \le y \le 2$),在坐标 $(x, y)$ 处都有一家巧克力店。其中也包括 Coco 和 Hanbyul 的店,Coco 的店位于 $(a, b)$,Hanbyul 的店位于 $(c, d)$。Coco 的村庄的道路有些特别:任何两家 $x$ 坐标之差和 $y$ 坐标之差均不超过 $1$ 的巧克力店之间都有一条道路相连,可以从一家店移动到另一家店。

Coco 正在和 Hanbyul 一起规划一条巧克力圣地巡礼路线。一条合法的圣地巡礼路线定义如下:

  • 从 Coco 的店开始,通过道路移动,并在 Hanbyul 的店结束。
  • 到达某家巧克力店所在的位置时,必须访问该店,且每家巧克力店最多只能访问一次。

Coco 对村里所有巧克力店出售的巧克力都进行了评分。圣地巡礼路线的得分是访问的所有巧克力店(包括 Coco 和 Hanbyul 的店)出售的巧克力评分之和。请帮 Coco 计算出所有可能的圣地巡礼路线中,得分最高路线的得分。

输入格式

第一行包含测试用例的数量 $T$。$(1 \le T \le 1\,000)$

每个测试用例的第一行包含整数 $N$。$(1 \le N \le 200\,000)$

接下来的两行给出每家巧克力店出售的巧克力的评分。设坐标 $(x, y)$ 处的巧克力店评分为 $s_{(x, y)}$,则第一行按顺序给出 $N$ 个整数 $s_{(1, 1)}$, $s_{(2, 1)}$, $\cdots$, $s_{(N, 1)}$,第二行按顺序给出 $N$ 个整数 $s_{(1, 2)}$, $s_{(2, 2)}$, $\cdots$, $s_{(N, 2)}$,整数之间用空格分隔。$(-1\,000 \le s_{(x, y)} \le 1\,000)$

下一行按顺序给出表示 Coco 的店和 Hanbyul 的店位置的四个整数 $a, b, c, d$,用空格分隔。$(1 \le a, c \le N;$ $1 \le b, d \le 2;$ $(a, b) \neq (c, d))$

所有测试用例的 $N$ 之和不超过 $1\,000\,000$。

输出格式

对于每个测试用例,在一行中输出所有可能的圣地巡礼路线中得分最高路线的得分。

样例

输入 1

1
5
0 10 20 30 40
-40 -30 -20 -10 0
1 1 5 2

输出 1

100

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.