AT_arc229_f.Angst for All Pairs 2

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN and a length-NN sequence of positive integers C=(C1,C2,…,CN)C=(C_1,C_2,\ldots,C_N).

You want to prepare one or more cards, as many as you like, and write one integer between 11 and NN (inclusive) on each of the front and back sides of each card, so that the following condition is satisfied.

  • No matter which distinct integers xx and yy between 11 and NN (inclusive) are chosen, there exists at least one card satisfying the following.
    • Exactly one of xx and yy is written on at least one side of that card.

It is allowed to write the same integer on the front and back of a single card.

Here, the cost of writing aa on the front and bb on the back of a card is Ca+CbC_a+C_b.

Find the minimum total cost required to satisfy the condition.

You are given TT test cases; solve each of them.

给你一个正整数 NN 和一个长度为 NN 的正整数序列 C=(C1,C2,…,CN)C=(C_1,C_2,\ldots,C_N)。

你需要制作一张或多张卡片(数量不限),并在每张卡片的正面和背面各写一个介于 11 到 NN(含)之间的整数,使得满足以下条件:

  • 对任意两个在 11 到 NN(含)范围内的不同整数 xx 和 yy,都存在至少一张卡片,满足:
    • xx 和 yy 中恰好有一个出现在该卡片的至少一面(正面或背面)上。

允许在一张卡片的正面和背面写相同的整数。

这里,若在某张卡片的正面写 aa、背面写 bb,则其花费为 Ca+CbC_a+C_b。

求满足上述条件所需的最小总花费。

你将得到 TT 组测试数据;请分别求解每组数据。

输入格式

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

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN
C1C_1 C2C_2 …\ldots CNC_N

输入从标准输入给出,格式如下:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例的格式如下:

NN
C1C_1 C2C_2 …\ldots CNC_N

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    3
    3
    3 2 5
    4
    5 6 7 8
    7
    12 42 21 10 29 33 18

    输出#1

    9
    23
    145

说明/提示

Sample 1 Explanation:
Consider the first test case.

By creating a card with 11 written on the front and 22 on the back, and a card with 22 written on the front and 22 on the back, the condition can be satisfied.

The total cost in this case is 3+2+2+2=93+2+2+2=9. It is impossible to satisfy the condition with a total cost less than 99, so output 99 on the first line.

Constraints

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤Ci≤1091\le C_i\le 10^9
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

通过制作一张正面写有 11、背面写有 22 的卡片,以及一张正面写有 22、背面写有 22 的卡片,即可满足条件。

此时总花费为 3+2+2+2=93+2+2+2=9。无法以低于 99 的总花费满足条件,因此在第一行输出 99。

约束条件

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤Ci≤1091\le C_i\le 10^9
  • 所有测试用例的 NN 之和不超过 2×1052\times 10^5。
  • 所有输入值均为整数。

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

首页