A. Salem and Sticks(暴力)

Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,a2,…,an.

For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from aa to bb is |a−b||a−b|, where |x||x| means the absolute value of xx.

A stick length aiai is called almost good for some integer tt if |ai−t|≤1|ai−t|≤1.

Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer tt and the total cost of changing is minimum possible. The value of tt is not fixed in advance and you can choose it as any positive integer.

As an answer, print the value of tt and the minimum cost. If there are multiple optimal choices for tt, print any of them.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the number of sticks.

The second line contains nn integers aiai (1≤ai≤1001≤ai≤100) — the lengths of the sticks.

Output

Print the value of tt and the minimum possible cost. If there are multiple optimal choices for tt, print any of them.

Examples

input

Copy

3
10 1 4

output

Copy

3 7

input

Copy

5
1 1 2 2 3

output

Copy

2 0

Note

In the first example, we can change 11 into 22 and 1010 into 44 with cost |1−2|+|10−4|=1+6=7|1−2|+|10−4|=1+6=7 and the resulting lengths [2,4,4][2,4,4]are almost good for t=3t=3.

In the second example, the sticks lengths are already almost good for t=2t=2, so we don't have to do anything.

题解:啥也不说了。暴力一波!

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int n,l,r,x,ans,sum,a[1111];
int main()
{
    cin>>n;
    l=100;
    ans=INF;
    for(int i=1;i<=n;i++)   
    {
        cin>>a[i];
        if(l>a[i])
            l=a[i];
        if(r<a[i])
            r=a[i];
    }
    for(int i=l;i<=r;i++)  //找出n个数中的最大值和最小值,依次暴力枚举
    {
        sum=0;
        for(int j=1;j<=n;j++)
            sum+=max(abs(a[j]-i)-1,0);
        if(sum<ans)
        {
            ans=sum;
            x=i;
        }
    }
    cout<<x<<" "<<ans<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值