AT_scpc2026_div2_b.SCSC Card Game

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

SCSC has NN members. Each member has one spade card and one club card. Member ii's spade card has integer SiS_i written on it, and their club card has integer CiC_i written on it.

The members of SCSC are standing in a line in the order from member 11 to member NN to play the SCSC card game. Terra, the host of the game, must choose two adjacent members and make them play one of the following two duels.

  • The two members each reveal the spade card with the smallest integer among their spade cards. The member who reveals the card with the larger integer wins. The losing member gives all of their club cards to the winning member and leaves.

  • The two members each reveal the club card with the smallest integer among their club cards. The member who reveals the card with the larger integer wins. The losing member gives all of their spade cards to the winning member and leaves.

Any cards that the leaving member does not give to the winning member are no longer used in the game. If there were members on both sides of the leaving member, those two members become adjacent to each other.

After N−1N-1 duels, exactly one member remains.

The last remaining member gives Terra one card with the smallest integer among their spade cards and one card with the smallest integer among their club cards, then leaves.

Let SsumS_{\mathrm{sum}} be the sum of the integers written on all spade cards initially held by all members, and let CsumC_{\mathrm{sum}} be the sum of the integers written on all club cards initially held by all members. Let SfS_f be the integer written on the spade card Terra receives at the end, and let CfC_f be the integer written on the club card Terra receives at the end. Then Terra's final score is (Ssum−Sf)(Csum−Cf)(S_{\mathrm{sum}} - S_f)(C_{\mathrm{sum}} - C_f).

Terra wants the final score to be as small as possible. Find the minimum possible score Terra can obtain.

SCSC 有 NN 名成员。每名成员各持有一张黑桃牌和一张梅花牌。第 ii 名成员的黑桃牌上写有一个整数 SiS_i,梅花牌上写有一个整数 CiC_i。

SCSC 的成员按编号从 11 到 NN 的顺序排成一列,进行 SCSC 牌类游戏。游戏主持人 Terra 必须选择两名相邻的成员,并让他们进行以下两种对决之一:

  • 两名成员各自展示其所有黑桃牌中数字最小的一张。展示数字较大者获胜。失败者将其全部梅花牌交给获胜者,然后离场。

  • 两名成员各自展示其所有梅花牌中数字最小的一张。展示数字较大者获胜。失败者将其全部黑桃牌交给获胜者,然后离场。

失败者未交给获胜者的那些牌将不再参与后续游戏。若离场成员两侧均有其他成员,则这两名成员变为相邻。

经过 N−1N-1 轮对决后,恰好只剩一名成员。

最后剩下的这名成员向 Terra 提交一张其所有黑桃牌中数字最小的黑桃牌,以及一张其所有梅花牌中数字最小的梅花牌,然后离场。

记 SsumS_{\mathrm{sum}} 为所有成员初始持有的黑桃牌上数字之和,CsumC_{\mathrm{sum}} 为所有成员初始持有的梅花牌上数字之和;记 SfS_f 为 Terra 最终收到的黑桃牌上的数字,CfC_f 为 Terra 最终收到的梅花牌上的数字。则 Terra 的最终得分为 (Ssum−Sf)(Csum−Cf)(S_{\mathrm{sum}} - S_f)(C_{\mathrm{sum}} - C_f)。

Terra 希望最终得分尽可能小。求 Terra 能获得的最小可能得分。

输入格式

The input is given from Standard Input in the following format:

NN
S1S_1 C1C_1
S2S_2 C2C_2
⋮\vdots
SNS_N CNC_N

输入从标准输入中按以下格式给出:

NN
S1S_1 C1C_1
S2S_2 C2C_2
⋮\vdots
SNS_N CNC_N

输出格式

Output the minimum possible score Terra can obtain.

输出Terra能够获得的最小可能得分。

输入输出样例

  • 输入#1

    2
    3 4
    4 5

    输出#1

    15

说明/提示

表示言語

/ /

Constraints

  • 1≤N≤5 0001 \leq N \leq 5\,000
  • 1≤Si,Ci≤50 0001 \leq S_i, C_i \leq 50\,000
  • For all 1≤i<j≤N1 \leq i < j \leq N, Si≠SjS_i \neq S_j and Ci≠CjC_i \neq C_j.
  • All given numbers are integers.

表示语言

/ /

限制条件

  • 1≤N≤5 0001 \leq N \leq 5\,000
  • 1≤Si,Ci≤50 0001 \leq S_i, C_i \leq 50\,000
  • 对于所有 1≤i<j≤N1 \leq i < j \leq N,有 Si≠SjS_i \neq S_j 且 Ci≠CjC_i \neq C_j。
  • 所有给定的数均为整数。

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

首页