AT_arc229_c.Sum of Average 2

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a length-NN sequence of positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N).

Find the minimum possible value of ∑i=1N−1⌊Ai+Ai+12⌋\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor after rearranging AA in any order.

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

给你一个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N)。

在对 AA 进行任意重排后,求 ∑i=1N−1⌊Ai+Ai+12⌋\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor 的最小可能值。

你将得到 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
A1A_1 A2A_2 …\ldots ANA_N

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

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

每个测试用例按以下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N

输出格式

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

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

输入输出样例

  • 输入#1

    4
    4
    1 2 4 3
    3
    4 4 4
    5
    3 1 4 1 5
    10
    278117031 167642909 517897721 148434323 567739597 319926999 481642530 659199879 252516557 49913403

    输出#1

    5
    8
    9
    2829561210

说明/提示

Sample 1 Explanation:
Consider the first test case.

For example, rearranging AA as (3,2,1,4)(3,2,1,4) gives ∑i=1N−1⌊Ai+Ai+12⌋=⌊52⌋+⌊32⌋+⌊52⌋=5\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor=\left\lfloor\frac52\right\rfloor+\left\lfloor\frac32\right\rfloor+\left\lfloor\frac52\right\rfloor=5.

No matter how AA is rearranged, the value of ∑i=1N−1⌊Ai+Ai+12⌋\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor is at least 55, so the answer is 55.

Constraints

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤Ai≤1091\le A_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 解释:
考虑第一个测试用例。

例如,将 AA 重排为 (3,2,1,4)(3,2,1,4),可得

∑i=1N−1⌊Ai+Ai+12⌋=⌊52⌋+⌊32⌋+⌊52⌋=5。\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor=\left\lfloor\frac52\right\rfloor+\left\lfloor\frac32\right\rfloor+\left\lfloor\frac52\right\rfloor=5。

无论 AA 如何重排,∑i=1N−1⌊Ai+Ai+12⌋\displaystyle \sum_{i=1}^{N-1}\left\lfloor\frac{A_i+A_{i+1}}2 \right\rfloor 的值均不小于 55,因此答案为 55。

约束条件

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

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

首页