Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)

简介: Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)

Ezzat has an array of n integers (maybe negative). He wants to split it into two non-empty subsequences a and b, such that every element from the array belongs to exactly one subsequence, and the value of f(a)+f(b) is the maximum possible value, where f(x) is the average of the subsequence x.


A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.


The average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence.


For example, the average of [1,5,6] is (1+5+6)/3=12/3=4, so f([1,5,6])=4.


Input

The first line contains a single integer t (1≤t≤103)— the number of test cases. Each test case consists of two lines.


The first line contains a single integer n (2≤n≤105).


The second line contains n integers a1,a2,…,an (−109≤ai≤109).


It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.


Output

For each test case, print a single value — the maximum value that Ezzat can achieve.


Your answer is considered correct if its absolute or relative error does not exceed 10−6.


Formally, let your answer be a, and the jury’s answer be b. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−6.


样例输入


4

3

3 1 2

3

-7 -6 -6

3

2 2 2

4

17 3 5 -3


样例输出


4.500000000

-12.500000000

4.000000000

18.666666667


题意


将一个给定的数组分成两个数组,将每个数组的和除以这个数组的个数,将两个数相加。

找一个最合理的分配方式使相加后的和最大,输出这个最大的和;


这个简单,就是把最大的拿出来,加上前面的平均数;


如果有测试点2,超限的,提醒一下不要用double,在数组定义里面


听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。

f58230e9f063709cf3167704f4efdf14.gif


有事你就q我;QQ2917366383


学习算法

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
  long long sum=0;int m;
    long long  c[100000];//这里如果用double会提示测试点2不能通过,甚至可能出现错误
  scanf("%d",&m);
    for(int i=1;i<=m;i++)
   scanf("%lld",&c[i]);
    sort(c+1,c+m+1);    
    for(int i=1;i<=m-1;i++)
    sum+=c[i];
printf("%.9f\n",(1.0*sum/(m-1)+c[m]));
  }
 } 


相关文章
|
9月前
|
机器学习/深度学习 人工智能 BI
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序
37 0
【CodeForces】Codeforces Round 857 (Div. 2) B
【CodeForces】Codeforces Round 857 (Div. 2) B
90 0
Codeforces Round 859 (Div. 4)题解
Codeforces Round 859 (Div. 4)题解
75 0
|
人工智能 BI
Codeforces Round #805 (Div. 3) 题解
Codeforces Round #805 (Div. 3) 题解
Codeforces Round #805 (Div. 3) 题解
|
人工智能 索引
Codeforces Round #806 (Div. 4) 题解
Codeforces Round #806 (Div. 4) 题解

热门文章

最新文章